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
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]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

[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>
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.