Jump to content

Problem


JackJack

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
Link to comment
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
Link to comment
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
Link to comment
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]
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.