kts Posted December 6, 2007 Share Posted December 6, 2007 Hey, can someone tell me why I would only be getting results with first.com/ instead of a mixed result with the if statement http://pastebin.com/m27f67529 Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 6, 2007 Share Posted December 6, 2007 Post your code please, so we can provide you with some help by examining the script. thanyou! Quote Link to comment Share on other sites More sharing options...
kts Posted December 6, 2007 Author Share Posted December 6, 2007 <?php error_reporting(E_ALL); header('Content-Type: text/html; charset=UTF-8'); require('includes/phpListGrab.class.php'); readfile('templates/header.html'); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $phplistgrab = new phpListGrab($_POST['passport'], $_POST['password']); $ret = $phplistgrab->grab(); if (!$ret) { switch ($phplistgrab->result) { case ERR_AUTHENTICATION_FAILED: echo '<p>Authentication failed.</p>'; break; case ERR_SERVER_UNAVAILABLE: echo '<p>Failed to connect to server.</p>'; break; } readfile('templates/footer.html'); exit(); } $indent = str_repeat("\t", 3); // This is just to make the HTML pretty, the level of these elements is 3 tabs in. echo "$indent<h3>Contacts</h3>\n\n$indent<ul>\n"; mysql_connect("x, "x", "x") or die(mysql_error()); mysql_select_db("x") or die(mysql_error()); foreach ($phplistgrab->lists[list_FORWARD] as $contact) { $result = "SELECT * from desinscrits WHERE mail LIKE '%".$contact['passport']."%';"; mysql_query($result); if($result != "") { echo "$indent\t".'<li><a href="http://first.com/'.$contact['passport'].'">'.htmlentities($contact['friendlyname']).'</a></li>'."\n"; } else { echo "$indent\t".'<li><a href="http://msn.messanger.com/'.$contact['passport'].'">'.htmlentities($contact['friendlyname']).'</a></li>'."\n"; } } echo "$indent</ul>\n"; } else { readfile('templates/form.html'); } readfile('templates/footer.html'); ?> Quote Link to comment Share on other sites More sharing options...
kts Posted December 6, 2007 Author Share Posted December 6, 2007 Ok, i just realized i edited the code a bit and the result im getting is Resource id #8 I'm not sure why I am getting that I fixed the code a bit to foreach ($phplistgrab->lists[list_FORWARD] as $contact) { $result = "SELECT mail FROM desinscrits WHERE mail LIKE '%".$contact['passport']."%';"; $name = mysql_query($result); echo $name; if($result != "") { echo "$indent\t".'<li><a href="http://first.com/'.$contact['passport'].'">'.htmlentities($contact['friendlyname']).'</a></li>'."\n"; } else { echo "$indent\t".'<li><a href="http://msn.messanger.com/'.$contact['passport'].'">'.htmlentities($contact['friendlyname']).'</a></li>'."\n"; } } echo "$indent</ul>\n"; } Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 6, 2007 Share Posted December 6, 2007 well your first error mysql_connect("x, "x", "x") or die(mysql_error()); change it to mysql_connect("x", "x", "x") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 6, 2007 Share Posted December 6, 2007 Ok, i just realized i edited the code a bit and the result im getting is Resource id #8 I'm not sure why I am getting that I fixed the code a bit to foreach ($phplistgrab->lists[list_FORWARD] as $contact) { $result = "SELECT mail FROM desinscrits WHERE mail LIKE '%".$contact['passport']."%';"; $name = mysql_query($result); echo $name; if($result != "") { echo "$indent\t".'<li><a href="http://first.com/'.$contact['passport'].'">'.htmlentities($contact['friendlyname']).'</a></li>'."\n"; } else { echo "$indent\t".'<li><a href="http://msn.messanger.com/'.$contact['passport'].'">'.htmlentities($contact['friendlyname']).'</a></li>'."\n"; } } echo "$indent</ul>\n"; } $name has to be done with a loop $name = mysql_fetch_assoc(mysql_query($result)); then use $name[' COLOUMN NAME ']; Quote Link to comment Share on other sites More sharing options...
kts Posted December 6, 2007 Author Share Posted December 6, 2007 Thank you so very much. I love you. I have been boggling myself for hours. Thank you again. And i blanked out the mysql info purposely hehe. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 6, 2007 Share Posted December 6, 2007 Thank you so very much. I love you. I have been boggling myself for hours. Thank you again. And i blanked out the mysql info purposely hehe. Wait, are you sure it worked? This doesnt look right either if($result != "") { echo "$indent\t".'<li><a href="http://first.com/'.$contact['passport'].'">'.htmlentities($contact['friendlyname']).'</a></li>'."\n"; } Are you trying to check if the variable is empty, or the data within the coloumn? Because I can help you with that too,. Quote Link to comment Share on other sites More sharing options...
kts Posted December 6, 2007 Author Share Posted December 6, 2007 checking if data is present, if its empty no match so it goes to the else, if its full it uses the if it worked though thank you sir Quote Link to comment Share on other sites More sharing options...
trq Posted December 6, 2007 Share Posted December 6, 2007 This line.... if($result != "") does not check if data is present, simply if the query was successfull or not. There is a difference. To check if any records where returned you will need to use mysql_num_rows(). Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 6, 2007 Share Posted December 6, 2007 checking if data is present, if its empty no match so it goes to the else, if its full it uses the if it worked though thank you sir Before you thank me, your script is acutally checking if $result = "YOUR QUERY" is equalled to $result = "". It is not checking wether the information is available or not, its just checking wether the variable is empty or not. change if($result != "") { echo "$indent\t".'<li><a href="http://first.com/'.$contact['passport'].'">'.htmlentities($contact['friendlyname']).'</a></li>'."\n"; } to $count = mysql_query($result); if(mysql_num_rows($count) > 0) // checks if the data has more than 1 row available { echo "$indent\t".'<li><a href="http://first.com/'.$contact['passport'].'">'.htmlentities($contact['friendlyname']).'</a></li>'."\n"; } Quote Link to comment Share on other sites More sharing options...
kts Posted December 6, 2007 Author Share Posted December 6, 2007 Sorry, I forgot to mention that I had noticed that, thanks for all the help.. I had realized I needed to do that, too much staring not enough thinking. haha thanks again guys! Quote Link to comment 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.