Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

echoing data from mySQL database for a report 1

Status
Not open for further replies.

BettyJo50

Technical User
Apr 25, 2002
47
US
Hi!

Here is my dumb question for the day. I have a database that has 3 separate project names in it. I would like to take this information and put it into a report, depending on which project the user would like to see. Only one project at a time. I can get the field names to come up in my table, but the actual information that is suppose to be on the report is blank. Does this make sense? Here is my code, if it helps. I know I'm missing some things, just can't figure out what. THANKS FOR YOUR HELP!! :)

<?
$hostname=&quot;11.111.1.111&quot;;
$user=&quot;$pass=&quot;me&quot;;
$database=&quot;qtso&quot;;
$table= &quot;serverrequest&quot;;
?>


<HTML>
<HEAD>
<TITLE>Request Report</TITLE>
</HEAD>

<BODY bgcolor=&quot;#ffffff&quot;>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>

<?
$result=(&quot;SELECT * FROM SERVERREQUEST WHERE Project='MDS'&quot;);
$row=mysql_fetch_array($result);
?>

<table width=&quot;75%&quot; border=&quot;1&quot; cellpadding=&quot;3&quot; height=&quot;76&quot; align=&quot;center&quot;>
<tr>
<td width=&quot;18%&quot;>Vendor Name:</td>
<td width=&quot;82%&quot;>
<?php echo $GET['Vendor'] ?>
</td>
</tr>

//There are more fields - like email, phone, address, city, state, etc.

</table>
<p>&nbsp;</p>
</body>
</html>
 
If I run my SQL statement as
select *
from SERVERREQUEST
where Project='MDS';

it returns exactly what I need....the specific project (mds) and all of it's fields. There are currently only 2 records and that's what it returned.

Thanks!!
 
I assume you are trying to get the contents from the GET vars. However, that won't work.

GET vars are sent to the PHP script from the browser. They have nothing to do with the information returned from a MySQL query.

$row = mysql_fetch_array($result);

$row is an array that contains the values of the db record. You need to refer to the content as $row['Vendor'] for example.

I think that's what's wrong. Just replace the $GET['Vendor'] with $row['Vendor'];
 
I replaced it $row['Vendor']; but it is still not working. Do you think I need to change this code completely? Right now it is:
<tr>
<td width=&quot;18%&quot;>Vendor Name:</td>
<td width=&quot;82%&quot;>
<?php echo $row['Vendor'] ?>
</td>
</tr>

Do I need a ; in there somewhere? Or maybe it is something else I need to look into closer. Maybe I'm having a problem with my connection that I am not seeing. I will have to check that out.

Thanks!!
 
BettyJo50,

1) It is advisable to include some error catching mechanism to notify you of MySQL errors. That will help to pinpoint what's going on.

$result=(&quot;SELECT * FROM SERVERREQUEST WHERE Project='MDS'&quot;) OR die(mysql_error().' in '.__FILE__.' line '.__LINE__);
$row=mysql_fetch_array($result) OR die(mysql_error().' in '.__FILE__.' line '.__LINE__);

2) You are missing the semicolon. Put it there.

3) You are not looping through the results. You said there may be multiple records.

Suggestion:
while ($row = mysql_fetch_array($result){
echo &quot;<tr>\n&quot;;
echo &quot;<td width=&quot;18%&quot;>Vendor Name:</td>\n&quot;;
echo &quot;<td width=&quot;82%&quot;>\n&quot;;
echo $row['Vendor'];
echo &quot;</td>\n</tr>\n&quot;;
}

The HTML here is generated by echo statements. A table row is created for every record in the database.

4) Check how many rows are in $result.
mysql_num_rows($result) returns the number of rows in the resultset.

5) Check the structure of the $row array. Are you using the right keys?
print_r($row) will show the keys and values.

Just a few things to do, but they should help to find out what's going wrong.
 
Thank you for your suggestions and help!! I will definitely try them.

Thanks again!! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top