Jump to content


Photo

Printing a row


  • Please log in to reply
9 replies to this topic

#1 Random

Random
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationIndiana

Posted 06 April 2003 - 01:38 AM

How do I print a row from mysql? This is the script I was trying ( newbie at this ):

[php:1:71284b16c1]<?php
print \"<BR><BR><BR><BR>\";
$conn = mysql_connect(\"localhost\", \"random\", \"random\") or die (\"Couldn\'t Connect...\");
print \"Connected!\";
$db = \"random\";
mysql_select_db($db, $conn) or die (\"Couldn\'t connect\");

$result = mysql_query( \"SELECT * FROM user_info \");
$fetch = mysql_fetch_row( $result );
print \" $fetch \";
mysql_close( $conn );
?>

[/php:1:71284b16c1]

It prints out: \"Connected! Array\"; where Connected is from the successful connect, and I guess $result is printing Array. Any help is appreciated. Thanks.

#2 LiamG

LiamG
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts
  • LocationMelbourne, Australia

Posted 06 April 2003 - 02:16 AM

First, it says \"Print\" because of the line [php:1:6c27594e10]print \"Connected!\";[/php:1:6c27594e10]If you don\'t want it to say that, delete the line! YAY! One down.

Next, it says array for a reason unknown to me, however if you put a @ before the comment mysql_fetch_array you might find it will supress that. I don\'t REALLY know though.

HTH,

LiamG.

#3 Random

Random
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationIndiana

Posted 06 April 2003 - 02:18 AM

I was just pointing out why it says connected :P that wasnt a problem hehe

#4 LiamG

LiamG
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts
  • LocationMelbourne, Australia

Posted 06 April 2003 - 02:20 AM

What about the array problem?

LiamG.

#5 Random

Random
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationIndiana

Posted 06 April 2003 - 02:32 AM

[php:1:10dbd8e8ef]<?php
$fetch = @mysql_fetch_row( $result );
?>[/php:1:10dbd8e8ef]

so it looks like that? if so that didn\'t work.

#6 LiamG

LiamG
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts
  • LocationMelbourne, Australia

Posted 06 April 2003 - 02:34 AM

Try putting it infront of the mysql_query.

LiamG.

ps - Shiva or someone might be able to more accurately answer this question later.

#7 Random

Random
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationIndiana

Posted 06 April 2003 - 02:54 AM

still didn\'t work. yeah I will wait for shiva to get on.

#8 DocSeuss

DocSeuss
  • Members
  • PipPipPip
  • Advanced Member
  • 73 posts
  • LocationTexas, USA

Posted 06 April 2003 - 03:17 AM

$fetch IS an array that is why the work array is printing out.

you would have to print each element sepeartly

print $row[0]. \", \". $row[1]. \", \" ect.

or you can use $row[\'fieldname\'] for each column in the table.

the way you have the code set up is only going to output the first row of the table if you want to print them all.

while($fetch = mysql_fetch_row($result)) {
print $row[0] . \", \" $row[1], ect..
}

I\'ve just used a comma to seperate each one but that all depends on how you want your output to be displayed on the screen.
"Unlimited budget? Great, for $5,000,0000 we will run your ad banner for one year"  ----Rasmus Lerdorf

#9 LiamG

LiamG
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts
  • LocationMelbourne, Australia

Posted 06 April 2003 - 04:05 AM

There you go, Doc answered it.

Thanks Doc!

LiamG.

#10 Random

Random
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts
  • LocationIndiana

Posted 16 April 2003 - 09:00 PM

Thanks Doc! I just checked it, and it worked like a charm :P




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users