Jump to content

Substract data from sql table


roma2509

Recommended Posts

Hello to every one.I have a database with brands that are separated in gategories like restaurants, pubs, taxi...I want to select from tabel a category and insert all filds in a div for any row from tabel that coresponde to category extracted.I dont know how to create the dynamic div with php.In attach you will see how look my div structure. I do the conection for database and selection of all fields for tabel for category and I insert the filds in the div that I will present now:

"<div id="categ">

    <div id="inside"><?php echo $row['brand_name']; ?></div>

    <div id="inside1"><a href="#"><img src="<?php echo $row['brand_logo']; ?>" /></a></div>

    <div id="inside2"><?php echo $row['short_desc']; ?> <a href="<?php echo $row['site_link']; ?>">continuare</a> </div>

    <div id="inside3"><a rel="shadowbox;width=405;height=340" title="Restaurant Daniel - New York, NY"  href="<?php echo $row['video_link']; ?>"><img src="img/tur_act.jpg" /></a></div>

    </div>

"

but how can I write a ciclic function or some thing like this to generate the divs that i present in attach for all rows from tabel that corespont for example to taxi category

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/201340-substract-data-from-sql-table/
Share on other sites

use a while loop to run through each of the sql select results:

$qry = "SELECT brand_name, brand_logo, site_link, video_link FROM tableName where catagory = 'Taxi'";
$result = mysql_query($qry) or die (mysql_error());
while ($row = mysql_fetch_assoc($result)){
?>
<div id="categ">
    <div id="inside"><?php echo $row['brand_name']; ?></div>
    <div id="inside1"><a href="#"><img src="<?php echo $row['brand_logo']; ?>" /></a></div>
    <div id="inside2"><?php echo $row['short_desc']; ?> <a href="<?php echo $row['site_link']; ?>">continuare</a> </div>
    <div id="inside3"><a rel="shadowbox;width=405;height=340" title="Restaurant Daniel - New York, NY"   href="<?php echo $row['video_link']; ?>"><img src="img/tur_act.jpg" /></a></div>
    </div> 
<?php } ?>

 

and please use the

 tags when posting code on here.

If i read this correctly, and my English is somewhat butchered. I think you want to display all the records that are inside the category "taxi" , "pubs" etc...

 

I have done this by modifying my database with a column called "category"  and then running a new query that will pull only those records.

 

[pseudocode]

query = "SELECT * FROM `brands` WHERE `category` = 'pubs'

 

foreach row in query {

    display div with queried results

}

[/pseudocode]

 

If this is close to what your talking about, reply back or try to be a little bit clearer & run spell check before submitting please.

use a while loop to run through each of the sql select results:

$qry = "SELECT brand_name, brand_logo, site_link, video_link FROM tableName where catagory = 'Taxi'";
$result = mysql_query($qry) or die (mysql_error());
while ($row = mysql_fetch_assoc($result)){
?>
<div id="categ">
    <div id="inside"><?php echo $row['brand_name']; ?></div>
    <div id="inside1"><a href="#"><img src="<?php echo $row['brand_logo']; ?>" /></a></div>
    <div id="inside2"><?php echo $row['short_desc']; ?> <a href="<?php echo $row['site_link']; ?>">continuare</a> </div>
    <div id="inside3"><a rel="shadowbox;width=405;height=340" title="Restaurant Daniel - New York, NY"   href="<?php echo $row['video_link']; ?>"><img src="img/tur_act.jpg" /></a></div>
    </div> 
<?php } ?>

 

and please use the

 tags when posting code on here.

 

haha, yea what he said  :)

use a while loop to run through each of the sql select results:

$qry = "SELECT brand_name, brand_logo, site_link, video_link FROM tableName where catagory = 'Taxi'";
$result = mysql_query($qry) or die (mysql_error());
while ($row = mysql_fetch_assoc($result)){
?>
<div id="categ">
    <div id="inside"><?php echo $row['brand_name']; ?></div>
    <div id="inside1"><a href="#"><img src="<?php echo $row['brand_logo']; ?>" /></a></div>
    <div id="inside2"><?php echo $row['short_desc']; ?> <a href="<?php echo $row['site_link']; ?>">continuare</a> </div>
    <div id="inside3"><a rel="shadowbox;width=405;height=340" title="Restaurant Daniel - New York, NY"   href="<?php echo $row['video_link']; ?>"><img src="img/tur_act.jpg" /></a></div>
    </div> 
<?php } ?>

 

and please use the

 tags when posting code on here.

 

Thank you wery match.But if I want to show only 5 ore 10 result per page what I need?some atribute to read how match rows are in the teable and asociate to some variable?

you would wrap a counter around it.

 

for ($i = $num_rows = mysql_num_rows($result); $i <= 10; $i++) {
    echo $i;
}

 

I want to show for exeample 10 results per page and generate a numeric list that will create a link to next page that will show me next result for this category on new page.

Archived

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

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