w00kie Posted April 24, 2006 Share Posted April 24, 2006 Hey, i have a DB with a list of gallery pictures.Now i want a script to display and let users know how many pictures are in the dababase, which i used mysql_num_fields for. Since all the images are listed in one row, i couldn't use num_rows.now i've tried to set up a script which will check for blank fields in the row, and if it has blank fields then it will decrement the number of images it echo's outFor instance, I have 10 images in my DB it echo's"There are 10 images in the database"Now, if i had 9 images, one blank field. I want it to say" There are 9 images in the database"So now it decrements down, and so fourth, Now i wanted to use && or, operators but my syntax is crap and i m not that very advanced at php, i would appreciate the help.[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$result = mysql_query("SELECT e_1, e_2, e_3, e_4, e_5, e_6, e_7, e_8, e_9, e_10 FROM f_images", $link);$num_rows = mysql_num_fields($result);if( $e_1 && $e_2 == "") {echo "There are : <B>";echo --$num_rows;echo "</b> Images in this group\n";}?>[/quote] Link to comment https://forums.phpfreaks.com/topic/8265-decrementing/ Share on other sites More sharing options...
w00kie Posted April 24, 2006 Author Share Posted April 24, 2006 Nevermind it seems i have solved my problem[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$result = mysql_query("SELECT e_1, e_2, e_3, e_4, e_5, e_6, e_7, e_8, e_9, e_10 FROM f_images", $link);$num_rows = mysql_num_fields($result);if($e_1=="") {echo "There are : <B>";--$num_rows;if($e_2=="") {--$num_rows;}if($e_3=="") {echo --$num_rows;}}?> [/quote] Link to comment https://forums.phpfreaks.com/topic/8265-decrementing/#findComment-30147 Share on other sites More sharing options...
wisewood Posted April 24, 2006 Share Posted April 24, 2006 that seems to be a very odd way of going about it.could you not just assign each group a unique number, and then SELECT * FROM table WHERE unique_number = $variable.$images_in_group = mysql_num_rows($query); Link to comment https://forums.phpfreaks.com/topic/8265-decrementing/#findComment-30150 Share on other sites More sharing options...
kenrbnsn Posted April 24, 2006 Share Posted April 24, 2006 It's a very strange way of doing things, but you can shorten your code considerably:[code]<?php$result = mysql_query("SELECT e_1, e_2, e_3, e_4, e_5, e_6, e_7, e_8, e_9, e_10 FROM f_images", $link);$num_rows = mysql_num_fields($result);$row = mysql_fetch_assoc($result);foreach($row as $k => $v) if ($v == '') $num_row--;echo $num_rows;?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/8265-decrementing/#findComment-30155 Share on other sites More sharing options...
w00kie Posted April 24, 2006 Author Share Posted April 24, 2006 [!--quoteo(post=368033:date=Apr 24 2006, 11:09 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Apr 24 2006, 11:09 AM) [snapback]368033[/snapback][/div][div class=\'quotemain\'][!--quotec--]It's a very strange way of doing things, but you can shorten your code considerably:[code]<?php$result = mysql_query("SELECT e_1, e_2, e_3, e_4, e_5, e_6, e_7, e_8, e_9, e_10 FROM f_images", $link);$num_rows = mysql_num_fields($result);$row = mysql_fetch_assoc($result);foreach($row as $k => $v) if ($v == '') $num_row--;echo $num_rows;?>[/code]Ken[/quote]Thanks for your responce ken, although i have images in e_2, e_5, e_6, yet it still displays '10' Link to comment https://forums.phpfreaks.com/topic/8265-decrementing/#findComment-30160 Share on other sites More sharing options...
kenrbnsn Posted April 24, 2006 Share Posted April 24, 2006 If you do[code]<?php$result = mysql_query("SELECT e_1, e_2, e_3, e_4, e_5, e_6, e_7, e_8, e_9, e_10 FROM f_images", $link);$row = mysql_fetch_assoc($result);echo '<pre>' . print_r($row,true) . '</pre>';?>[/code]What is displayed? If you post that, we might be able to provide more assistance.Ken Link to comment https://forums.phpfreaks.com/topic/8265-decrementing/#findComment-30162 Share on other sites More sharing options...
w00kie Posted April 24, 2006 Author Share Posted April 24, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Array( [e_1] => one.jpg [e_2] => [e_3] => [e_4] => [e_5] => [e_6] => [e_7] => [e_8] => [e_9] => [e_10] => )[/quote] Link to comment https://forums.phpfreaks.com/topic/8265-decrementing/#findComment-30163 Share on other sites More sharing options...
kenrbnsn Posted April 24, 2006 Share Posted April 24, 2006 I created a test script with an array that matches what you posted.[code]<?php$row = Array('e_1' => 'one.jpg', 'e_2' => '', 'e_3' => '', 'e_4' => '', 'e_5' => '', 'e_6' => '', 'e_7' => '', 'e_8' => '', 'e_9' => '', 'e_10' => '');$num_rows = count($row);echo $num_rows.'<br>';foreach($row as $k=>$v) if ($v == '') $num_rows--;echo $num_rows;?>[/code]When I run this script, it shows[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]101[/quote]Which is what I expect. Do you have any other code in your script you're not posting?Ken Link to comment https://forums.phpfreaks.com/topic/8265-decrementing/#findComment-30176 Share on other sites More sharing options...
w00kie Posted April 24, 2006 Author Share Posted April 24, 2006 No Ken, i ran the php script in a seperate PHP file.When i run your array script i get 10, 1 also.but when i run the script you previously posted, it results as 10.even though now i've added .jpgs in e_1, e_2, e_3, e_4 of the database.& also, I dont know if this helps but i previously stated that the images were all on the same row, not individual rows, i dont know if that would change anything. Link to comment https://forums.phpfreaks.com/topic/8265-decrementing/#findComment-30178 Share on other sites More sharing options...
kenrbnsn Posted April 24, 2006 Share Posted April 24, 2006 I think I found the problem... Just a minor misspelled variable in one of my examples... :-([code]<?php$result = mysql_query("SELECT e_1, e_2, e_3, e_4, e_5, e_6, e_7, e_8, e_9, e_10 FROM f_images", $link);$num_rows = mysql_num_fields($result);$row = mysql_fetch_assoc($result);foreach($row as $k => $v) if ($v == '') $num_rows--; // I had $num_row originallyecho $num_rows;?>[/code]You can also just add up the entries which are not blank:[code]<?php$result = mysql_query("SELECT e_1, e_2, e_3, e_4, e_5, e_6, e_7, e_8, e_9, e_10 FROM f_images", $link);$num_rows = 0$row = mysql_fetch_assoc($result);foreach($row as $k => $v) if ($v != '') $num_rows++;echo $num_rows;?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/8265-decrementing/#findComment-30196 Share on other sites More sharing options...
w00kie Posted April 24, 2006 Author Share Posted April 24, 2006 [!--quoteo(post=368075:date=Apr 24 2006, 12:53 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Apr 24 2006, 12:53 PM) [snapback]368075[/snapback][/div][div class=\'quotemain\'][!--quotec--]I think I found the problem... Just a minor misspelled variable in one of my examples... :-([code]<?php$result = mysql_query("SELECT e_1, e_2, e_3, e_4, e_5, e_6, e_7, e_8, e_9, e_10 FROM f_images", $link);$num_rows = mysql_num_fields($result);$row = mysql_fetch_assoc($result);foreach($row as $k => $v) if ($v == '') $num_rows--; // I had $num_row originallyecho $num_rows;?>[/code]You can also just add up the entries which are not blank:[code]<?php$result = mysql_query("SELECT e_1, e_2, e_3, e_4, e_5, e_6, e_7, e_8, e_9, e_10 FROM f_images", $link);$num_rows = 0$row = mysql_fetch_assoc($result);foreach($row as $k => $v) if ($v != '') $num_rows++;echo $num_rows;?>[/code]Ken[/quote]Thank you Ken, and thank you for being so patient <3 Link to comment https://forums.phpfreaks.com/topic/8265-decrementing/#findComment-30197 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.