<?php
//start session
session_start();
//store cmpid from querystring
$_SESSION['session_cmpid'] = $_GET['cmpid'];
$campaign=$_SESSION['session_cmpid'];
//connect to db server
require dirname(__FILE__).'/core/dbconnect_vps.php';
//select db
$database = "atdata";
//define sql
$sql_campaignredirect = "SELECT web_confirmurl
FROM tbl_marketingcampaign
WHERE marketingcampaignid = '$campaign'";
//run sql
$result = mysql_db_query($database,$sql_campaignredirect)
or die (mysql_error());
//fetch data
$campaign_url = mysql_fetch_array($result);
//display data
echo 'URL is '.$campaign_url;
?>
Instead of displaying the data (http://www.domain.com), it returns:
URL is Array
I know it's probably a simple oversigt on my part but can't seem to
figure it out.
Thanks..........James
Looking at this might help:
$link = mysql_connect('gonzo', $USR);
if( $link ) {
mysql_select_db( $DB, $link );
if( $sql ) {
$sql = ereg_replace( ";$", "", $sql );
$sql = ereg_replace( "\\\\", "", $sql );
$result = mysql_query( $sql, $link );
if( $result ) {
echo( "<p>Results: for '$sql;'.</p>\n" );
if( $num = mysql_num_rows( $result ) ) {
echo( "<pre>\n" );
while( $array = mysql_fetch_row( $result ) ) {
while( list($key, $val) = each( $array ) ) {
echo "$val | ";
} # end while
}
Michael.
>Instead of displaying the data (http://www.domain.com), it returns:
>
>URL is Array
that's correct $campaign_url is an array because mysql_fetch_array()
returns an array ;-)
try this:
echo 'URL is '.$campaign_url['web_confirmurl'];
Regards
Marian
--
Tipps und Tricks zu PHP, Coaching und Projektbetreuung
http://www.heddesheimer.de/coaching/
I understand now. Thanks!
Am I 'fetching' the data correctly by using mysql_fetch_array(), or is
there better way?
I understand now. Thanks!
I prefer to use mysql_fetch_assoc() because you get ONLY the associative
indices. If you use mysql_fetch_array() you get the associative indices, but
you also get their numeric equivalents, for example:
//Suppose the query returned the following database items: user_id,
username, password
$query_string = "SELECT * FROM tbl_login";
$result=mysql_query($query_string);
while ($row=mysql_fetch_array($result)) {
//Do something with $row['user_id'], $row['username'], $row['password']
}
But in the above example code, $row[0] also equals $row['user_id'], $row[1]
equals $row['username'], etc.
It doesn't affect you for a simple example like this, but sometimes I have
needed to loop through all of the elements in $row using a foreach
statement, and the numeric indices messed me up.
Just a thought...
Douglas Abernathy