We help IT Professionals succeed at work.

PHP echo sql result

patrickm12981
on
I'm not able to get the result of the second query $Result to echo out, what am I missing?

Thanks in advance


$sqlstr = mysql_query("SELECT * FROM Roster");
while($row=mysql_fetch_array($sqlstr)){

$Result = mysql_query("Select Count(*) AS 1stMain from Race_Results where `1` = ".$row['Car_Number']."");


echo "<table border=0 align='center'>";
echo "</td><td rowspan=8>";
echo $row['Image'];
echo "</td><th width=300>";
echo "<u>Details</u>";
echo "</th>";
echo "<th width=300>";
echo "<u>YTD Stats</u>";
echo "</th>";
echo "<th width=300>";
echo "<u>Overall Stats</u>";
echo "</th></tr><tr><td>";
echo "<b>Car Number: </b>" .$row['Car_Number'];
echo "</td><td>";
echo "<b>1st in Main: </b>" .$Result;
echo "</td><td>";
echo "<b>1st in Main: </b>";

Open in new window

Comment
Watch Question

Commented:
it's because you didn't fetch the result.
try
list($Result) = mysql_fetch_row(mysql_query("Select Count(*) AS 1stMain from Race_Results where `1` = ".$row['Car_Number'].""));
Avinash ZalaWeb Expert

Commented:
Try this query:

$Result = mysql_query("Select Count(*) AS 1stMain from Race_Results where `1` = '".$row['Car_Number']."'");


Hope this helps,
Addy
Avinash ZalaWeb Expert

Commented:
and then after add this line:


$data  = mysql_fetch_row($Result);

So with this line you will get the row you want..

Hope this helps,
Addy

Author

Commented:
szewkam - no change

addywatson - I get "array" outputed
$Result = mysql_query("Select Count(*) AS 1stMain from Race_Results where `1` = '".$row['Car_Number']."'");
$data  = mysql_fetch_row($Result);


echo "<b>1st in Main: </b>" .$data;

Open in new window

Author

Commented:
Here is the page: http://rmdcra.org/Roster.php
Commented:
It is very strange that my suggestion doesn't work. Try:
list($Result) = mysql_fetch_row(mysql_query("Select Count(*) AS 1stMain from Race_Results where `1` = '".$row['Car_Number']."'"));
echo $result;

or


$Result = mysql_query("Select Count(*) AS 1stMain from Race_Results where `1` = '".$row['Car_Number']."'");
$data  = mysql_fetch_row($Result);


echo "<b>1st in Main: </b>" .$data[0];
Software Architect
Top Expert 2010
Commented:
I would use mysql_fetch_array() instead of mysql_fetch_row(),  you then need to choose which column from the row to echo.

so it would look more like this:





$Result = mysql_query("Select Count(*) AS 1stMain from Race_Results where `1` = '".$row['Car_Number']."'");
$data  = mysql_fetch_array($Result);


echo "<b>1st in Main: </b>" . $data['1stMain'];

Open in new window

Author

Commented:
Andyc75 - It works, that's the way I started but I guess my query was wrong from the get go. This would allow me to pull more results at once as well which I will need to do, then I can just call out the columns that I need.

Thanks!