Jump to content

Printing a row


Random

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.

Link to comment
https://forums.phpfreaks.com/topic/309-printing-a-row/
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.

Link to comment
https://forums.phpfreaks.com/topic/309-printing-a-row/#findComment-971
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.

Link to comment
https://forums.phpfreaks.com/topic/309-printing-a-row/#findComment-978
Share on other sites

  • 2 weeks later...

Archived

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

×
×
  • Create New...

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.