bumba000 Posted September 6, 2008 Share Posted September 6, 2008 Hi All, I have a db connection and am getting results here. The problem seems to be with my in_array. I have a table called marks. I have a record in there with the value of 22 in the website_id field. The network_name field of the record has the name Blinklist in it. Below is an example of my table and a single record. Below that is the code in question. As you can see, Blinklist is in the record but I get the echo response "Its Not Here". Why? Thanks in advance, John MARKS: website_id | network_name | date 22 | Blinklist | 1220677200 $webSiteID = $rowGetClient['website_id']; $getMarksList = mysql_query("SELECT * FROM marks WHERE website_id = 22"); if(!$getMarksList) { die("Get List Failed: " . mysql_error()); }?> <?php while ($array = mysql_fetch_array($getMarksList)){ if (in_array("Blinklist", $array)) { echo "Its Here";}else{echo "Its Not Here";} echo '<br>'."ID=:" . $webSiteID; } ?> Link to comment https://forums.phpfreaks.com/topic/123030-ifin_array-broken-please-help/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 6, 2008 Share Posted September 6, 2008 When a comparison fails it is always a good idea to display what the actual value(s) are to make sure they are what you expect. I recommend using var_dump() so that you know the length of the data so that things like white-space/non-displayable characters on the end of them can be detected. Link to comment https://forums.phpfreaks.com/topic/123030-ifin_array-broken-please-help/#findComment-635267 Share on other sites More sharing options...
bumba000 Posted September 6, 2008 Author Share Posted September 6, 2008 Thanks for that. Here are my results. I'm not sure what to make of them. array( { [0]=> string(2) "22" ["website_id"]=> string(2) "22" [1]=> string(9) "BlinkList" ["network_name"]=> string(9) "BlinkList" [2]=> string(1) "1" ["partner_id"]=> string(1) "1" [3]=> string(10) "1220677200" ["date"]=> string(10) "1220677200" } Link to comment https://forums.phpfreaks.com/topic/123030-ifin_array-broken-please-help/#findComment-635283 Share on other sites More sharing options...
PFMaBiSmAd Posted September 6, 2008 Share Posted September 6, 2008 I would guess that this is because by default mysql_fetch_array() returns the results as both an associative array and a numeric array. Try it using mysql_fetch_assoc() Link to comment https://forums.phpfreaks.com/topic/123030-ifin_array-broken-please-help/#findComment-635294 Share on other sites More sharing options...
bumba000 Posted September 6, 2008 Author Share Posted September 6, 2008 That didnt work. On the bright side I am only getting results for those website id's that are in the marks table. So I know that the query is functioning properly. My code hasn't changed from above except for the addition of the commented out var_dump($array);. What am I missing here? Thank you, John Link to comment https://forums.phpfreaks.com/topic/123030-ifin_array-broken-please-help/#findComment-635316 Share on other sites More sharing options...
PFMaBiSmAd Posted September 6, 2008 Share Posted September 6, 2008 Take a closer look at the code and data. Blinklist is not equal to BlinkList. I thought I looked at the spelling after you posted the var_dump output, but I guess I did not look close enough. Link to comment https://forums.phpfreaks.com/topic/123030-ifin_array-broken-please-help/#findComment-635322 Share on other sites More sharing options...
bumba000 Posted September 6, 2008 Author Share Posted September 6, 2008 OMG what a jerk! I can't believe I did that. I am trying soooo hard and doing my absolute best to learn this stuff. Little things like this . . . ERRRRR. That's cool though. Thank you so much for seeing that. John Link to comment https://forums.phpfreaks.com/topic/123030-ifin_array-broken-please-help/#findComment-635332 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.