Jump to content

Archived

This topic is now archived and is closed to further replies.

Random

Printing a row

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

What about the array problem?

 

LiamG.

Share this post


Link to post
Share on other sites

[php:1:10dbd8e8ef]<?php

$fetch = @mysql_fetch_row( $result );

?>[/php:1:10dbd8e8ef]

 

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

Share this post


Link to post
Share on other sites

Try putting it infront of the mysql_query.

 

LiamG.

 

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

$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.

Share this post


Link to post
Share on other sites

There you go, Doc answered it.

 

Thanks Doc!

 

LiamG.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.