coalduststar Posted December 22, 2009 Share Posted December 22, 2009 Hi I'm really close to doing this but i suck. I need to check this column in a database which is either a load of zeroes or ones (or both). If there are no ones at all I want it to echo "<dd class='warn'>Presently there are no post graduate options available for this subject at this location.</dd>"; But if there's an instance of even one one then I want it to display the records. I keep thinking it's right but then the fields either empty or something- i think i need to do something with the array function but it's basically black magic to me- below is my code: <dl class="list0r"> <dt><span class="bold">Undergraduate:</span></dt> <?php if (empty($rsArtsCoursesWithOptionsB)){ echo "<dd class='warn'>Presently there are no post graduate options available for this subject at this location.</dd>"; echo $rsArtsCoursesWithOptionsB; }else{ do { ?> <dd><span class="options"><a href="<?php echo $row_rsArtsCoursesWithOptionsB['url_link']; ?>" target="_blank"><?php echo $row_rsArtsCoursesWithOptionsB['fac_title']; ?></a> <?php echo $row_rsArtsCoursesWithOptionsB['ucas_code']; ?></span></dd> <?php } while ($row_rsArtsCoursesWithOptionsB = mysql_fetch_assoc($rsArtsCoursesWithOptionsB)); }?> </dl> <br /> <dl class="list0r"> <dt><span class="bold">Postgraduate:</span></dt> <?php if (empty($row_rsArtsCoursesWithOptionsPostB['post'])){ echo "<dd class='warn'>Presently there are no post graduate options available for this subject at this location.</dd>"; }else{ do { ?> <dd><span class="options"><?php echo $row_rsArtsCoursesWithOptionsPostB['ucas_code']; ?><a href="<?php echo $row_rsArtsCoursesWithOptionsPostB['url_link']; ?>" target="_blank"><?php echo $row_rsArtsCoursesWithOptionsPostB['fac_title']; ?></a></span></dd> <?php } while ($row_rsArtsCoursesWithOptionsPostB = mysql_fetch_assoc($rsArtsCoursesWithOptionsPostB)); }?> </dl> Link to comment https://forums.phpfreaks.com/topic/186021-check-if-a-column-is-populated/ Share on other sites More sharing options...
teynon Posted December 22, 2009 Share Posted December 22, 2009 if (!strpos($rsArtsCoursesWithOptionsB, "1")) { Warning! } Link to comment https://forums.phpfreaks.com/topic/186021-check-if-a-column-is-populated/#findComment-982314 Share on other sites More sharing options...
megaresp Posted December 22, 2009 Share Posted December 22, 2009 I need to check this column in a database which is either a load of zeroes or ones (or both). PHP's empty function just tells you if a variable is empty, rather than whether or not a string contains all zeros. A zero in a string is character rather than a number, and therefore actually exists (i.e. it's the character zero). What you've literally said is you want to check whether or not an entire column in a database contains any 1s. Put another way, does the following column contain any values > zero? 1. 0 2. 1 3. 0 4. 0 5. 1 6. 0 7. 0 etc... That's something best done via a MySQL query. Let's assume the field in question is named rsArtsCoursesWithOptionsB, and the table is called courses. Run the following query... Select count(*) as postgrad from Courses where rsArtsCoursesWithOptionsB > 0 The value in postgrad will either be null (i.e. no instances of rsArtsCoursesWithOptionsB contain a value > 0), or a number greater than zero. It may be a little more complex than this if you only want to test records for a specific subsection of courses. For example... Select count(*) as postgrad from Courses where rsArtsCoursesWithOptionsB > 0 and courseType = 'English' I made up the field courseType. Your database table will need a similar field that you can use to identify one subset of courses from another. Link to comment https://forums.phpfreaks.com/topic/186021-check-if-a-column-is-populated/#findComment-982340 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.