Jump to content

Archived

This topic is now archived and is closed to further replies.

JackJack

Problem

Recommended Posts

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
[code]
<?
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>";

}
}


?>

[/code]



Thank you

JJ

Share this post


Link to post
Share on other sites
What is your problem? You posted a large chunk of code with no explanation of why you posted.

Ken

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
You can definiatly shorten it by miles:
[code]<?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>";

}

?>[/code]

Share this post


Link to post
Share on other sites

×

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.