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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

echoing results from a database

Status
Not open for further replies.

rskuse

Technical User
Jul 18, 2002
74
GB
Can anyone tell me where I'm going wrong? I have six columns in a MySQL table (all containing data) and I want to be able to display them on a web page.
I've tried the following script but all it returns are errors :eek:(

<?php
$dbcnx = mysql_connect(&quot;localhost&quot;,&quot;root&quot;,&quot;&quot;);
$query = mysql_query(&quot;select * from line_filters);
$result = mysql_db_query(&quot;awi_products&quot;,&quot;$query&quot;);
while($row=mysql_fetch_row($result)){
$akey = $row[0];
$model = $row[1];
$port = $row[2];
$flowm3 = $row[3];
$flowcfm7 = $row[4];
$flowcfm10 = $row[5];
$net = $row[6];
echo &quot;<table><tr><td>$model</td><td>$port</td><td>$flowm3
</td><td>$flowcfm7</td><td>$flowcfm10</td><td>$net</td></tr>
</table>&quot;;
};
mysql_free_result($result);
?>

Any ideas? Thankyou

Rach
 
What are the actual errors?

If it was me I would use

Code:
<?php
$dbcnx = mysql_connect(&quot;localhost&quot;,&quot;root&quot;,&quot;&quot;); or die (&quot;Can't connect!&quot;); //is the pwd blank?
mysql_select_db($db_name) or die (&quot;Can't select database!&quot;);
$query = mysql_query(&quot;SELECT * FROM line_filters);
$result = mysql_query($query, $dbcnx) or die (&quot;Bad query!&quot;);
while($row = mysql_fetch_array($result)) {
    $akey = $row[0];
    $model = $row[1];
    $port = $row[2];
    $flowm3 = $row[3];
    $flowcfm7 = $row[4];
    $flowcfm10 = $row[5];
    $net = $row[6];
    echo &quot;<table>\n
             <tr>\n
                 <td>$model</td>\n
                 <td>$port</td>\n
                 <td>$flowm3</td>\n
                 <td>$flowcfm7</td>\n
                 <td>$flowcfm10</td>\n
                 <td>$net</td>\n
             </tr>\n
          </table>\n&quot;;
}
?>

Someone please let me know if there is a better way. [smurf]
01101000011000010110010001110011
 
Sorry, scratch that...

<?php
$dbcnx = mysql_connect(&quot;localhost&quot;,&quot;root&quot;,&quot;&quot;); or die (&quot;Can't connect!&quot;); //is the pwd blank?
mysql_select_db($db_name) or die (&quot;Can't select database!&quot;);
$query = &quot;SELECT * FROM line_filters&quot;;
$result = mysql_query($query, $dbcnx) or die (&quot;Bad query!&quot;);
while($row = mysql_fetch_array($result)) {
$akey = $row[0];
$model = $row[1];
$port = $row[2];
$flowm3 = $row[3];
$flowcfm7 = $row[4];
$flowcfm10 = $row[5];
$net = $row[6];
echo &quot;<table>\n
<tr>\n
<td>$model</td>\n
<td>$port</td>\n
<td>$flowm3</td>\n
<td>$flowcfm7</td>\n
<td>$flowcfm10</td>\n
<td>$net</td>\n
</tr>\n
</table>\n&quot;;
}
?> [smurf]
01101000011000010110010001110011
 
Thankyou very much - it is now working!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top