Jump to content

Recommended Posts

Hi All,

 

I have a 'Newspaper' in a game I'm coding. My plan was to have an edition every week and on average 15 articles a week. I would set this out like so. .

 

<?
$select_paper=mysql_query("SELECT * FROM paper WHERE id=1");
while($the=mysql_fetch_object($select_paper)){
?>
<table width=100% class=table>

<tr>
<td>
<td width=50% style=border: none; background-color: transparent; valign=top>


			<table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000 class='main' align=center>
				<tr>
				  <td width=500 class='tableheading'><?php echo "$the->title"; ?><center>
				  </center></td>
			  </tr>
				<tr >
					<td class="profilerow" align=left><center><?php echo "$the->news"; ?>
</td>
			  </tr>
				<tr >
					<td  class="subtableheader" align=left><center><?php echo "Article By $the->by - $the->date"; ?>
</td>
			  </tr>
		  </table>
<br>
	</td>
<? } ?>

 

With that repeated for 15 articles per edition.

 

BUT! To save time, space and complication, I would rather do it using something like this. . 

$select = mysql_query("SELECT * FROM paper WHERE edition=1 ORDER by id ASC");
$num = mysql_num_rows($select);

 

Could someone tell me how to intergrate this with the layout tables as show in code #1?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/257692-order-article-by-id/
Share on other sites

have you tried putting the sql you want in place of the current sql, that should do it really, perhaps with LIMIT 15 tacked on the end of the sql so only 15 records return.

 

$select_paper=mysql_query("SELECT * FROM paper WHERE edition=1 ORDER by id ASC LIMIT 15");

Link to comment
https://forums.phpfreaks.com/topic/257692-order-article-by-id/#findComment-1320739
Share on other sites

well i think because it has a half finished table in the html part

 

try this:

 

<?
$select_paper=mysql_query("SELECT * FROM paper WHERE id=1");
while($the=mysql_fetch_object($select_paper)){
?>


			<table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000 class='main' align=center>
				<tr>
				  <td width=500 class='tableheading'><?php echo "$the->title"; ?><center>
				  </center></td>
			  </tr>
				<tr >
					<td class="profilerow" align=left><center><?php echo "$the->news"; ?>
</td>
			  </tr>
				<tr >
					<td  class="subtableheader" align=left><center><?php echo "Article By $the->by - $the->date"; ?>
</td>
			  </tr>
		  </table>
<br>

<? } ?>

Link to comment
https://forums.phpfreaks.com/topic/257692-order-article-by-id/#findComment-1320743
Share on other sites

No the first code I posted works absolutely fine, but i have to re-enter it for each article that's written, as you see

$select_paper=mysql_query("SELECT * FROM paper WHERE id=1");

I have to do it for id=2 and so on. When i change that line of code to the order by it doesn't show anything.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/257692-order-article-by-id/#findComment-1320751
Share on other sites

Yeah already have done if you see the second code in my first post. My code looks like this now

 

<table class="Main" width="65%" cellpadding="0" cellspacing="0">
<tr><td class="Tableheading">Newspaper</td></tr>
<tr><td class="subtableheader"><img src="images/newspaper.jpg" alt="paper"/></td></tr>
</table>

<?
$select = mysql_query("SELECT * FROM paper WHERE edition=1 ORDER by id ASC");
$the = mysql_num_rows($select);

?>
<table width=100% class=table>

<tr>
<td>
<td width=50% style=border: none; background-color: transparent; valign=top>


			<table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000 class='main' align=center>
				<tr>
				  <td width=500 class='tableheading'><?php echo "$the->title"; ?><center>
				  </center></td>
			  </tr>
				<tr >
					<td class="profilerow" align=left><center><?php echo "$the->news"; ?>
</td>
			  </tr>
				<tr >
					<td  class="subtableheader" align=left><center><?php echo "Article By $the->by - $the->date"; ?>
</td>
			  </tr>
		  </table>
<br>
	</td>


</html>

Link to comment
https://forums.phpfreaks.com/topic/257692-order-article-by-id/#findComment-1320758
Share on other sites

you still need the while statement to loop through the record set:

<table class="Main" width="65%" cellpadding="0" cellspacing="0">
<tr><td class="Tableheading">Newspaper</td></tr>
<tr><td class="subtableheader"><img src="images/newspaper.jpg" alt="paper"/></td></tr>
</table>

<table width=100% class=table>

<?
$select = mysql_query("SELECT * FROM paper WHERE edition=1 ORDER by id ASC");

while($the=mysql_fetch_object($select_paper)){

?>
<tr>
<td>
<td width=50% style=border: none; background-color: transparent; valign=top>


			<table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000 class='main' align=center>
				<tr>
				  <td width=500 class='tableheading'><?php echo "$the->title"; ?><center>
				  </center></td>
			  </tr>
				<tr >
					<td class="profilerow" align=left><center><?php echo "$the->news"; ?>
</td>
			  </tr>
				<tr >
					<td  class="subtableheader" align=left><center><?php echo "Article By $the->by - $the->date"; ?>
</td>
			  </tr>
		  </table>
	</td>
</tr>
<?
}
?>
</table>
</html>

Link to comment
https://forums.phpfreaks.com/topic/257692-order-article-by-id/#findComment-1320762
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.