Jump to content

order data in php page from mysql


chery

Recommended Posts

How do I edit this php to show data by order of ProductID?

[code]<?

$sSQL="SELECT * FROM Products";
$rs=mysql_query($sSQL);
$rsproducts=mysql_num_rows($rs);
?>
<? if (!($rsproducts==0))
{
?>
[/code]

I would really appreciate some imput on how to do this as I really have no idea
Link to comment
https://forums.phpfreaks.com/topic/29217-order-data-in-php-page-from-mysql/
Share on other sites

[quote author=taith link=topic=117103.msg477517#msg477517 date=1165065655]
[code]<?
$rs=mysql_query("SELECT * FROM Products ORDER BY ProductID");

while($row=mysql_fetch_array($rs)){
}
?>[/code]
[/quote]

Unfortunately that creates an empty page showing none of the products - any ideas on what I am doing wrong.

Should I be editing this part instead?
[code]<table width="75%" border="1" align="center">
<?
 
  while($rsProducts=mysql_fetch_array($rs))
  {
    WriteProductRow($rsProducts[1]);
  }
?>
</table>
[/code]
Unfortunately that creates an empty page showing none of the products - any ideas on what I am doing wrong.

You need ot make it show something :P

[code]
<?
$rs=mysql_query("SELECT * FROM Products ORDER BY ProductID");
echo "<table><tr><td></td></tr>"; // header or whatever.
while($row=mysql_fetch_array($rs)){
echo "<tr><td>$row['field'];</td></tr>";
}
?>
[/code]
[quote author=ataria link=topic=117103.msg477523#msg477523 date=1165066972]
Unfortunately that creates an empty page showing none of the products - any ideas on what I am doing wrong.

You need ot make it show something :P

[code]
<?
$rs=mysql_query("SELECT * FROM Products ORDER BY ProductID");
echo "<table><tr><td></td></tr>"; // header or whatever.
while($row=mysql_fetch_array($rs)){
echo "<tr><td>$row['field'];</td></tr>";
}
?>
[/code]

[/quote]

That's what I was asking about: <table width="75%" border="1" align="center">
<?
 
  while($rsProducts=mysql_fetch_array($rs))
  {
    WriteProductRow($rsProducts[1]);
  }
?>
</table>
[quote author=chery link=topic=117103.msg477525#msg477525 date=1165067064]
[quote author=ataria link=topic=117103.msg477523#msg477523 date=1165066972]
Unfortunately that creates an empty page showing none of the products - any ideas on what I am doing wrong.

You need ot make it show something :P

[code]
<?
$rs=mysql_query("SELECT * FROM Products ORDER BY ProductID");
echo "<table><tr><td></td></tr>"; // header or whatever.
while($row=mysql_fetch_array($rs)){
echo "<tr><td>$row['field'];</td></tr>";
}
?>
[/code]

[/quote]

That's what I was asking about: <table width="75%" border="1" align="center">
<?
 
  while($rsProducts=mysql_fetch_array($rs))
  {
    WriteProductRow($rsProducts[1]);
  }
?>
</table>
[/quote]


It would be alot neater if you added the table in the php.
so.
[code]
<?php
$rs=mysql_query("SELECT * FROM `Products` ORDER BY `ProductID`");

echo "<table width=75% border=1 align=center>";
 
  while($rsProducts=mysql_fetch_array($rs))
  {
    WriteProductRow($rsProducts[1]);
  }

echo "</table>";
?>
[/code]

you need the query in there too. :P


it should work now.

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.