Jump to content


Photo

Problem


  • Please log in to reply
5 replies to this topic

#1 JackJack

JackJack
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 07 April 2006 - 08:50 AM

Well this code is really long (only has 2 shops and i need to have about 15). Also for every item there is it posts another Table saying "name type, price".

Please Help
<? 
include("../inc/headers.inc.php");

$title = "Shops";

echo "<a href=shops.php?shop=owl target=mainframe>Eeylops Owl Emporium</a><br>";
echo "<a href=shops.php?shop=flourish target=mainframe>Flourish and Blotts</a><br>";

if ($shop == "owl") {
                            $owlsel = mysql_query("SELECT * FROM items WHERE slot='owl' and owner=0 order by price asc");
                   while ($item = mysql_fetch_array($owlsel)){
echo "
<br><br>

<table border='0' cellpadding='0' cellspacing='0' width='100%'>

<th width='34%' align='center' height='25' bgcolor=#cccccc>

<h4>Name</h4>

</td> 

<th width='33%' align='center' height='25' bgcolor=#cccccc>

<h4>Type</h4>

</td> 

<th width='33%' align='center' height='25' bgcolor=#cccccc>

<h4>Price</h4>

</td>


<td align='center' height='25'>

$item[name]

</td>


<td align='center' height='25'>

$item[type]

</td>


<td align='center' height='25'>

$item[price]

</td>";

}
}

if ($shop == "flourish") {
                            $flourishsel = mysql_query("SELECT * FROM items WHERE slot='flourish' and owner=0 order by price asc");
                   while ($item = mysql_fetch_array($flourishsel)){
echo "
<table border='0' cellpadding='0' cellspacing='0' width='100%'>

<th width='34%' align='center' height='25' bgcolor=#cccccc>

<h4>Name</h4>

</td> 

<th width='33%' align='center' height='25' bgcolor=#cccccc>

<h4>Type</h4>

</td> 

<th width='33%' align='center' height='25' bgcolor=#cccccc>

<h4>Price</h4>

</td>


<td align='center' height='25'>

$item[name]

</td>


<td align='center' height='25'>

$item[type]

</td>


<td align='center' height='25'>

$item[price]

</td>";

}
}


?>





Thank you

JJ

#2 JackJack

JackJack
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 07 April 2006 - 02:43 PM

Bumpety Bump

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 07 April 2006 - 03:24 PM

What is your problem? You posted a large chunk of code with no explanation of why you posted.

Ken

#4 JackJack

JackJack
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 07 April 2006 - 03:31 PM

The problem is

If there is more than object in the MySql database then it posts another line with

Name Type Price

On it.


Also the code is really long and i need to add about 8x more stuff in so i was wondering if anyone could shorten it a bit please.


Thank you


JJ

#5 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 07 April 2006 - 04:00 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Also the code is really long and i need to add about 8x more stuff in so i was wondering if anyone could shorten it a bit please.[/quote]

you can't just post code and ask us to fix it up for you....
you need to shorten it yourself and then explain what you need help on

and FYI your problem is that you're putting the row for NAME PRICE etc inside your while loop
start the table first then put the while loop
and end the table after the loop

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 07 April 2006 - 04:03 PM

You can definiatly shorten it by miles:
<?php

$title = "Shops";

echo "<a href=shops.php?shop=owl target=mainframe>Eeylops Owl Emporium</a><br>";
echo "<a href=shops.php?shop=flourish target=mainframe>Flourish and Blotts</a><br>";
//rest of shop links here!

$sql = mysql_query("SELECT * FROM items WHERE slot='$shop' and owner=0 order by price asc");
while ($item = mysql_fetch_array($sql))
{
    echo "<br>
<br>
<table border='0' cellpadding='0' cellspacing='0' width='100%'>
<th width='34%' align='center' height='25' bgcolor=#cccccc>
<h4>Name</h4>
</td>
<th width='33%' align='center' height='25' bgcolor=#cccccc>
<h4>Type</h4>
</td>
<th width='33%' align='center' height='25' bgcolor=#cccccc>
<h4>Price</h4>
</td>
<td align='center' height='25'>$item[name]</td>
<td align='center' height='25'>$item[type]</td>
<td align='center' height='25'>$item[price]</td>";

}

?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users