Jump to content

jakebur01

Members
  • Posts

    885
  • Joined

  • Last visited

Everything posted by jakebur01

  1. How can I optimize this to make it run better. As of now it will not even do a few zip codes. Is there any way to like sleep in between each loop or something? $result = mysql_query("SELECT * FROM zip_code where `state_prefix` = 'OK'", $db) or die(mysql_error()); while($myrow = mysql_fetch_array ($result)) { $zip=$myrow['zip_code']; $html = file_get_html('http://www.my-site.com/test.asp?transaction=search&template=map_search&search1=0&pwidth=400&pheight=700&proxIconId=400&proxIcons=1&search2=0&search3=1&country=US&searchQuantifier=AND&address=&city=&stateProvince=+&postalCode=$zip&radius=500&x=78&y=16'); $i = 0; $tmp = $html->find('span[class=mqEmp], span[class=Black11]'); $cnt = count($tmp) - 1; foreach($tmp as $e) { if($i > 0 && $i < $cnt){ echo $e->plaintext . '<br>'; } $i++; } }
  2. Wait I think I got it. I added this in: $cnt = count($tmp); $cnt = $cnt-1;
  3. For some reason it is not excluding the last row. However, it is excluding the first. - Jake
  4. nevermind... Got it. THANKS!! $i = 0; $tmp = $html->find('span[class=mqEmp], span[class=Black11]'); $cnt = count($tmp); foreach($tmp as $e) { if($i > 0 && $i < $cnt){ echo $e->plaintext . '<br>'; } $i++; }
  5. PHP Parse error: syntax error, unexpected '}'
  6. How could I get this to exclude the first and last row? foreach($html->find('span[class=mqEmp], span[class=Black11]') as $e) echo $e->plaintext . '<br>'; Example: if the above returns... 112 test drive 99999 bob smith 384 california circle new park, CA 99999 john doe 384 california circle rockport, CA 94939 User assumes all risk of use. My Company, MapQuest and their suppliers assume no responsibility for any loss resulting from such use. How could I get rid of the first and last lines?
  7. Would it be smart to use strtolower() when inserting a username into a database and also use it when comparing? if (isset($_POST['userid']) && isset($_POST['password'])) { // if the user has just tried to log in $userid = strtolower($_POST['userid']); $password = $_POST['password']; require("newlife_data.inc"); if (mysqli_connect_errno()) { echo 'Connection to database failed:'.mysqli_connect_error(); exit(); } $query = 'select * from life_useraccount ' ."where Username='$userid' " ." and Password=sha1('$password') " ." and Active='Y'"; $result = $db_conn->query($query); if ($result->num_rows >0 ) { }
  8. Man, you are amazing. It works perfect. Thank you. Where are some good places to learn more about MySQL queries?
  9. Hi, I am trying to query the friend table (life_approval)columns(Id, UserId1, UserId2, and Approve) and see who all is a friend of the variable $q. I am trying to do this by checking both columns, if $q is a friend to someone..... he/she could be in either column. When a friend invite is stored in this table, the person the invite is sent to is stored in UserId1. {which my attempt appears to be pulling everyone out of the table in columns UserId1 and UserId2} The second query is supposed to be collecting information on the friend. I was trying to do that by using ( WHERE `Username` = 'UserId1 from the first query OR `Username` = 'UserId2' from the first query. Thanks, Jake
  10. I tried using DISTINCT, but that did not do the trick. SELECT DISTINCT UserId1, UserId2 FROM life_approval WHERE (`UserId2`='$q' OR `UserId1`='$q') AND `Approved` = 'Approved'
  11. I tried using DISTINCT, but that did not do the trick. SELECT DISTINCT UserId1, UserId2 FROM life_approval WHERE (`UserId2`='$q' OR `UserId1`='$q') AND `Approved` = 'Approved'
  12. My table for displaying members has been working ok when querying all members. I have been trying to add an extra loop that will make the table only display members that are friends of a specific member. My problem is that it is grabbing the same member twice. For example if Fred is UserId1 and Tom is UserId2, then row 2 Joe is UserId1 and Fred is UserId2. It will display Fred twice. Also, I cannot get my <tr>'s to work correctly. echo '<table width="100%" border="0">'; $getimages = mysql_query("SELECT UserId1, UserId2 FROM life_approval WHERE (`UserId2`='$q' OR `UserId1`='$q') AND `Approved` = 'Approved'", $db); if(!$getimages) die("Cannot execute query. " . mysql_error()); $countRows = mysql_num_rows($getimages); $i = 0; if ($countRows > 0) { while ($rowimages = mysql_fetch_assoc($getimages)) { $result = mysql_query("SELECT Username, Company, Country, State, Link FROM life_useraccount WHERE (`Username`='$rowimages[userId1]' OR `Username`='$rowimages[userId2]') ", $db) or die(mysql_error()); if ($i % 3 == 0) echo ($i > 0? '</tr>' : '') . '<tr>'; while ($myrow = mysql_fetch_array($result)){ //$id=$myrow["Id"]; echo '<td><center><div class="product"><a href="profile.php?q='.$myrow['Username'].'"><img src="'.$myrow['Link'].'" width="145" border="0" /></a></div><b>'.$myrow["Company"].'</b><br />'.$myrow["State"].'<br />'.$myrow["Country"].'</center></td>'; } if ($i == $countRows - 1) echo '</tr>'; $i++; } } echo '</table>';
  13. My table for displaying members has been working ok when querying all members. I have been trying to add an extra loop that will make the table only display members that are friends of a specific member. My problem is that it is grabbing the same member twice. For example if Fred is UserId1 and Tom is UserId2, then row 2 Joe is UserId1 and Fred is UserId2. It will display Fred twice. Also, I cannot get my <tr>'s to work correctly. echo '<table width="100%" border="0">'; $getimages = mysql_query("SELECT UserId1, UserId2 FROM life_approval WHERE (`UserId2`='$q' OR `UserId1`='$q') AND `Approved` = 'Approved'", $db); if(!$getimages) die("Cannot execute query. " . mysql_error()); $countRows = mysql_num_rows($getimages); $i = 0; if ($countRows > 0) { while ($rowimages = mysql_fetch_assoc($getimages)) { $result = mysql_query("SELECT Username, Company, Country, State, Link FROM life_useraccount WHERE (`Username`='$rowimages[userId1]' OR `Username`='$rowimages[userId2]') ", $db) or die(mysql_error()); if ($i % 3 == 0) echo ($i > 0? '</tr>' : '') . '<tr>'; while ($myrow = mysql_fetch_array($result)){ //$id=$myrow["Id"]; echo '<td><center><div class="product"><a href="profile.php?q='.$myrow['Username'].'"><img src="'.$myrow['Link'].'" width="145" border="0" /></a></div><b>'.$myrow["Company"].'</b><br />'.$myrow["State"].'<br />'.$myrow["Country"].'</center></td>'; } if ($i == $countRows - 1) echo '</tr>'; $i++; } } echo '</table>';
  14. It worked with this: $sql = mysql_query("SELECT UserId1, UserId2 FROM life_approval WHERE (`UserId1` = '{$_SESSION['valid_user']}' AND `UserId2`='$q' OR `UserId2` = '{$_SESSION['valid_user']}' AND `UserId1`='$q') AND `Approved` = 'Approved'"); That is incredible. Now, I can really get some stuff done. Thank you all so much, I have been wanting to figure this out.
  15. Should it be similar to this? $sql = mysql_query("SELECT userId1, userId2 FROM life_approval WHERE (`userId1` = '{$_SESSION['valid_user']}' AND `UserId2`='$user_profile' OR `userId2` = '{$_SESSION['valid_user']}')AND `UserId1`='$user_profile' AND `approve` = 'Approved'");
  16. So, will this check both ways? $sql = mysql_query("SELECT userId1, userId2 FROM life_approval WHERE (`userId1` = '{$_SESSION['valid_user']}' OR `userId2` = '{$_SESSION['valid_user']}') AND `approve` = 'Approved'"); I should have posted this in mysql. I will take care to do that next time.
  17. Sorry... I am trying to check and see if $_SESSION[valid_user] and $user_profile are friends correction: WHERE `UserId2`='$_SESSION[valid_user]' AND `UserId1`='$user_profile' AND `Approve` = 'Approved' and WHERE `UserId1`='$_SESSION[valid_user]' AND `UserId2`='$user_profile' AND `Approve` = 'Approved'
  18. Could someone please show me a better way to do this so I will not have to make 2 queries out of it? <?PHP $sql = mysql_query("SELECT UserId1 FROM life_approval WHERE `UserId2`='$_SESSION[valid_user]' AND `Approve` = 'Approved'"); $num = mysql_num_rows($sql); if ($num > 0) { // we are good, this user is a friend } elseif { $sql = mysql_query("SELECT UserId2 FROM life_approval WHERE `UserId1`='$_SESSION[valid_user]' AND `Approve` = 'Approved'"); $num = mysql_num_rows($sql); if ($num > 0) { // we are good, this user is a friend } } else { //do nothing, this is not a friend } ?>
  19. How should I query this table to select the friends of a member? Could I make it happen all in one query? members (Id, UserId1, UserId2, Approved)
  20. Using the first table, how should I query to select all the friends of a particular member? Would I have to run 2 separate queries? Like: select UserId2 from friend_table where Approved = invite_accepted and UserId1 = $Username while { select * from user_table where Username=$myrow[username] } then, select UserId1 from friend_table where Approved = invite_accepted and UserId2 = $Username while { select * from user_table where Username=$myrow[username] }
  21. I keep complicating things when trying to figure out how I should send messages and invites between members. The way I was trying to do my invites was to have a table (Id, UserId1, UserId2, Approved). I would mark the Approved as 1 when the invite was first sent. Then mark it as 3 if the invite was accepted and 2 if declined. This is basically how I was trying to setup my friends table. It didn't work very well when people was submit multiple invites to each other. Also, my messages table was setup like (Id, Userd1, UserId2, Subject, Message).
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.