473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

HELP - mysql_fetch_array

I am new to PHP and am trying to run a simple query and display the
result, with no luck. Here is the code I am using.

<?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
Jul 17 '05 #1
5 2002
james wrote:
I am new to PHP and am trying to run a simple query and display the
result, with no luck. Here is the code I am using.

<?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.
Jul 17 '05 #2
On 17 Jun 2004 13:01:33 -0700, ja***@diroddi.com (james) wrote:
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/
Jul 17 '05 #3
Marian Heddesheimer <17*************@spamgourmet.com> wrote in message news:<vk********************************@4ax.com>. ..
On 17 Jun 2004 13:01:33 -0700, ja***@diroddi.com (james) wrote:
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


I understand now. Thanks!

Am I 'fetching' the data correctly by using mysql_fetch_array(), or is
there better way?
Jul 17 '05 #4
Marian Heddesheimer <17*************@spamgourmet.com> wrote in message news:<vk********************************@4ax.com>. ..
On 17 Jun 2004 13:01:33 -0700, ja***@diroddi.com (james) wrote:
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


I understand now. Thanks!

Am I 'fetching' the data correctly by using mysql_fetch_array(), or is
there better way?
Jul 17 '05 #5

"james" <ja***@diroddi.com> wrote in message
news:15**************************@posting.google.c om...
Marian Heddesheimer <17*************@spamgourmet.com> wrote in message

news:<vk********************************@4ax.com>. ..
On 17 Jun 2004 13:01:33 -0700, ja***@diroddi.com (james) wrote:
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


I understand now. Thanks!

Am I 'fetching' the data correctly by using mysql_fetch_array(), or is
there better way?


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

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris | last post by:
Sorry to post so much code all at once but I'm banging my head against the wall trying to get this to work! Does anyone have any idea where I'm going wrong? Thanks in advance and sorry again...
2
by: TheKeith | last post by:
I'm just learning php and set up a sample mysql db to practice with. I have the following script and cannot for the life of me figure out why it is printing each field of the row twice? I checked...
15
by: Good Man | last post by:
Hey there I have a dumb question.... Let's say i have a database full of 4000 people.... I select everything from the database by: $result = mysql_query("SELECT * FROM People");
0
by: mlw | last post by:
Hi, im working on a pretty basic friends system for a website, so far it is all working but i have a Friends of Friends feature - which works to an extent but because of the way my queries are set...
9
by: Petr Vileta | last post by:
Hi, I'm new here and excuse me if this question was be here earlier. I have a simple code <html><body> <?php <?php $link = mysql_connect("localhost", "user", "password") or die("Grr: " ....
1
by: danxavier | last post by:
I successfuly installed dd.php and sajax.php files. It runs fine, but I would like to link the $items to an image. I called the field in mysql with the link "pic". Any help would be AWESOME!!! I've...
23
by: casper christensen | last post by:
Hi I run a directory, where programs are listed based on the number of clicks they have recieved. The program with most clicks are placed on top and so on. Now I would like people to be apple to...
9
by: dajava | last post by:
Hi, Sorry for this beginner's question. I do not know PHP and write for my friend. He has never been a professional programmer. He studied C and PHP with some books and made a bulletin...
5
by: fruityfreak | last post by:
What languages is this in??? <?php session_start(); require('db.php'); mysql_connect(MACHINE, USER, ''); mysql_select_db(DBNAME); //Obtaining session variables (From do_login.php)
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.