roma2509 Posted May 11, 2010 Share Posted May 11, 2010 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] Quote Link to comment https://forums.phpfreaks.com/topic/201340-substract-data-from-sql-table/ Share on other sites More sharing options...
Muddy_Funster Posted May 11, 2010 Share Posted May 11, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/201340-substract-data-from-sql-table/#findComment-1056303 Share on other sites More sharing options...
sharp.mac Posted May 11, 2010 Share Posted May 11, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/201340-substract-data-from-sql-table/#findComment-1056309 Share on other sites More sharing options...
sharp.mac Posted May 11, 2010 Share Posted May 11, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/201340-substract-data-from-sql-table/#findComment-1056310 Share on other sites More sharing options...
roma2509 Posted May 11, 2010 Author Share Posted May 11, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/201340-substract-data-from-sql-table/#findComment-1056319 Share on other sites More sharing options...
sharp.mac Posted May 11, 2010 Share Posted May 11, 2010 you would wrap a counter around it. for ($i = $num_rows = mysql_num_rows($result); $i <= 10; $i++) { echo $i; } Quote Link to comment https://forums.phpfreaks.com/topic/201340-substract-data-from-sql-table/#findComment-1056330 Share on other sites More sharing options...
roma2509 Posted May 11, 2010 Author Share Posted May 11, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/201340-substract-data-from-sql-table/#findComment-1056367 Share on other sites More sharing options...
sharp.mac Posted May 11, 2010 Share Posted May 11, 2010 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. http://www.phpeasystep.com/phptu/29.html Quote Link to comment https://forums.phpfreaks.com/topic/201340-substract-data-from-sql-table/#findComment-1056387 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.