timmah1 Posted May 5, 2007 Share Posted May 5, 2007 I am doing a website similiar to MySpace, but for a certain group of people. It has a friends list and bulletins. I can login and see bulletins from people on my "friends" list, but I cannot see my own. This is the code that I am using. What am I doing wrong? Any help would be greatly appreciated. Maybe this might help better. When I login, my driverID is 5, one of my friends is driverID 6. Both of these driverID have posted a bulletin, but when I echo the driverID, I only receive the 6, when I should be getting the 5 also. <? include "dbConfig.php"; $server = "xxx"; // server to connect to. $database = "xxx"; // the name of the database. $db_user = "xxx"; // mysql username to access the database with. $db_pass = "xxx"; // mysql password to access the database with. $table = "bulletins"; // the table that this script will set up and use. // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); $friend = "SELECT * FROM friends WHERE driverID = '5' AND approved = 'y' GROUP BY 'driverID' "; $result8 = mysql_query($friend); $numberall = mysql_Numrows($result8); if ($numberall==0) { echo ""; } while($row8 = mysql_fetch_array( $result8 )){ $bulletin = "SELECT * FROM $table ORDER BY bulletinID DESC LIMIT 5"; $result7 = mysql_query($bulletin); $numberall = mysql_Numrows($result7); while($row7 = mysql_fetch_array( $result7 )){ if ($row7[driverID]==$row8[friendID]) { echo "$row7[driverID]"; } } } ?> Quote Link to comment Share on other sites More sharing options...
timmah1 Posted May 5, 2007 Author Share Posted May 5, 2007 Anybody have any ideas? I know my coding skills aren't great, but please, anyone have any insight? Quote Link to comment Share on other sites More sharing options...
benjaminbeazy Posted May 5, 2007 Share Posted May 5, 2007 your $numberall should be $numberall = mysql_num_rows($result8); same with others, its mysql_num_rows, not Numrows Quote Link to comment Share on other sites More sharing options...
timmah1 Posted May 5, 2007 Author Share Posted May 5, 2007 Thanks. I altered the code so that it's more legible, and I thought it would function, but I'm still getting the same result. // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // Select all friends for this person $result = mysql_query("SELECT * FROM friends WHERE driverID AND friendID = 5") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { if ($row[approved]=='y') { //Select all bulletins for this person's friends $result1 = mysql_query("SELECT * FROM $table") or die(mysql_error()); while($row1 = mysql_fetch_array( $result1 )) { print "$row1[driverID]<br>"; } } else { echo "No Friends"; } } Quote Link to comment Share on other sites More sharing options...
benjaminbeazy Posted May 5, 2007 Share Posted May 5, 2007 SELECT * from $table should be SELECT * from table Quote Link to comment Share on other sites More sharing options...
benjaminbeazy Posted May 5, 2007 Share Posted May 5, 2007 // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // Select all friends for this person $result = mysql_query("SELECT * FROM friends WHERE driverID = '5' AND friendID = '5'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { if ($row[approved]=='y') { //Select all bulletins for this person's friends $result1 = mysql_query("SELECT * FROM table") or die(mysql_error()); while($row1 = mysql_fetch_array( $result1 )) { print "$row1['driverID']<br>"; } } else { echo "No Friends"; } } Quote Link to comment Share on other sites More sharing options...
timmah1 Posted May 5, 2007 Author Share Posted May 5, 2007 OK, I appreciate the help, I really do, but that's not the issue $table is pre-defined $server = "localhost"; // server to connect to. $database = "xxx"; // the name of the database. $db_user = "xxx"; // mysql username to access the database with. $db_pass = "xxx"; // mysql password to access the database with. $table = "bulletins"; // the table that this script will set up and use. I can select the tables, I can pull out the information, what it's not doing is grabbing and showing my id as well as the others that are approved on my list. My driverID is 5, on my list is driverID 6, when I query the bulletins database, it should pull everything from driverID 5 and driverID 6, but it's only showing driverID 6. How do I get it to show my driverID as well? Quote Link to comment Share on other sites More sharing options...
benjaminbeazy Posted May 5, 2007 Share Posted May 5, 2007 can u post your most current code, your db structure or a var dump would help a lot too Quote Link to comment Share on other sites More sharing options...
timmah1 Posted May 5, 2007 Author Share Posted May 5, 2007 My current code <? include "dbConfig.php"; $server = "localhost"; // server to connect to. $database = "xxx"; // the name of the database. $db_user = "xxx"; // mysql username to access the database with. $db_pass = "xxx"; // mysql password to access the database with. $table = "bulletins"; // the table that this script will set up and use. // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // Select all friends for this person $result = mysql_query("SELECT * FROM friends WHERE driverID AND friendID = 5") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { if ($row[approved]=='y') { //Select all bulletins for this person's friends $result1 = mysql_query("SELECT * FROM $table WHERE driverID = $row[friendID]") or die(mysql_error()); while($row1 = mysql_fetch_array( $result1 )) { print "$row1[driverID]<br>"; } } else { echo "No Friends"; } } ?> My db structure friendID varchar(255) latin1_swedish_ci driverID varchar(255) latin1_swedish_ci approved varchar(10) latin1_swedish_ci Not sure how to do a var dump Quote Link to comment Share on other sites More sharing options...
benjaminbeazy Posted May 5, 2007 Share Posted May 5, 2007 please try this and tell me what you get... <? include "dbConfig.php"; $server = "localhost"; // server to connect to. $database = "xxx"; // the name of the database. $db_user = "xxx"; // mysql username to access the database with. $db_pass = "xxx"; // mysql password to access the database with. $table = "bulletins"; // the table that this script will set up and use. // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // Select all friends for this person $result = mysql_query("SELECT * FROM friends WHERE driverID = '5' AND friendID = '5'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { if ($row['approved']=='y') { $friend_id = $row['friendID']; //Select all bulletins for this person's friends $result1 = mysql_query("SELECT * FROM bulletins WHERE driverID = '$friendID'") or die(mysql_error()); while($row1 = mysql_fetch_array( $result1 )) { print "$row1[driverID]<br>"; } } else { echo "No Friends"; } } ?> Quote Link to comment Share on other sites More sharing options...
benjaminbeazy Posted May 5, 2007 Share Posted May 5, 2007 possibly change this $result = mysql_query("SELECT * FROM friends WHERE driverID = '5' AND friendID = '5'") or die(mysql_error()); to this... $result = mysql_query("SELECT * FROM friends WHERE friendID = '5'") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
timmah1 Posted May 5, 2007 Author Share Posted May 5, 2007 Nothing, blank screen Quote Link to comment Share on other sites More sharing options...
timmah1 Posted May 5, 2007 Author Share Posted May 5, 2007 With this code, it just prints out '5', but not the 6 // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // Select all friends for this person $result = mysql_query("SELECT * FROM friends WHERE friendID = '5'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { if ($row['approved']=='y') { $friend_id = $row['friendID']; //Select all bulletins for this person's friends $result1 = mysql_query("SELECT * FROM bulletins WHERE driverID = '$friend_id'") or die(mysql_error()); while($row1 = mysql_fetch_array( $result1 )) { print "$row1[driverID]<br>"; } } else { echo "No Friends"; } } ?> Quote Link to comment Share on other sites More sharing options...
benjaminbeazy Posted May 5, 2007 Share Posted May 5, 2007 ok, i think i got ya now, try.... $result = mysql_query("SELECT * FROM friends WHERE driverID = '5'") or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
timmah1 Posted May 5, 2007 Author Share Posted May 5, 2007 Almost, now it only prints out the '6' I have been racking my head with this for the past week. I really appreciate all the help Quote Link to comment Share on other sites More sharing options...
benjaminbeazy Posted May 5, 2007 Share Posted May 5, 2007 $result = mysql_query("SELECT * FROM friends WHERE driverID = '5' OR driverID = '6'") or die(mysql_error()); i'm not sure this is going to work how you want it in the long run however... do u have phpmyadmin? Quote Link to comment Share on other sites More sharing options...
timmah1 Posted May 5, 2007 Author Share Posted May 5, 2007 Yes I do have phpmyadmin. That's probably not going to work since those numbers are actually variables being passed. They won't always be 5 or 6 Quote Link to comment Share on other sites More sharing options...
benjaminbeazy Posted May 5, 2007 Share Posted May 5, 2007 exactly you need to define the variable of the users id and then have your table set up so his id can be associated with his friends and vice versa, im not sure if it is set up like that without seeing more info about the db in phpmyadmin, click on the database name. then click export and click go. this will give you the sql to build your db, copy and paste and i will see what i can figure out for you Quote Link to comment Share on other sites More sharing options...
timmah1 Posted May 5, 2007 Author Share Posted May 5, 2007 When someone logs in, the session is the driverID, which in this case is '5' So the actual code reads like this: $result = mysql_query("SELECT * FROM friends WHERE driverID = '$row[driverId]'") or die(mysql_error()); Here is my database: -- -- Table structure for table `friends` -- CREATE TABLE `friends` ( `ID` int(11) NOT NULL auto_increment, `friendID` varchar(255) NOT NULL default '', `driverID` varchar(255) NOT NULL default '', `approved` varchar(10) NOT NULL default '', KEY `ID` (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=112 ; -- -- Dumping data for table `friends` -- INSERT INTO `friends` VALUES (88, '6', '5', 'y'); INSERT INTO `friends` VALUES (106, '5', '6', 'y'); 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.