czukoman20 Posted August 25, 2007 Share Posted August 25, 2007 Once again.. i am a noob at php. so please just help me out. no smerks or stuff like that. Anyhow. what i have is this I have users table. with usernames and info on those users. The info that i have setup for this portion is userid_2 What i have planned for this is to call up that userid_2 from everyuser in a sequence. like this user1: userid_2 = 1 user2: userid_2 = 2 user3: userid_3 = 3 now i would like it to basically record all of these numbers.. (not add them.. subtract.. nothin like that) just record them. Then in the .php file. I want to have an if statement saying that if userid_2 = 1 echo user1's information then display an image. if userid_2 = 2 echo user2's information then display a different image i currently don't have anything coded. on account of that i would like your guys help. b4 i totally screw it up.. then get lost. and having to rewrite it all again. (i know thats how most people start out.) but thats the miracle of these forums. for people to help people like me. So help is greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/66692-solved-databasecoding-issue/ Share on other sites More sharing options...
Fadion Posted August 25, 2007 Share Posted August 25, 2007 Probably is is me, but i cant understand what u want. What is userid_2, a database column which is going to hold the id of the users? If yes then make it primary key with auto_increment feature to have it act as a real id. The part: "if (userid_2 = 1) echo user1 information" is going to be hard-coded, i mean ure going to write if statements for each userid_2 possibility? And where is the variable userid_2 coming from, a url variable? Please explain it in detail but more clear as right now i cant understand i correctly to give u some code examples. Quote Link to comment https://forums.phpfreaks.com/topic/66692-solved-databasecoding-issue/#findComment-334127 Share on other sites More sharing options...
czukoman20 Posted August 25, 2007 Author Share Posted August 25, 2007 http://www.czartgaming.com/testpages/help/database1.jpg http://www.czartgaming.com/testpages/help/database2.jpg ok lemmme try to explain this a bit more. What i want to do. I will insert the values into the userid_2 column. so dont worry about that. in the .php file. i would like it to get the users datatable info on everyone's userid_2 column. (look at the pictures) then make it so if anybody's userid_2 = 1 it will take that persons username.. and display it. along with displaying that persons username. I would like to display a banner/image under that. and continue with this if the userid_2 = ... other values. nobody will have the same number. look at the pictures to help u in understanding. because i think i have fully explained what i'm invisioning. Quote Link to comment https://forums.phpfreaks.com/topic/66692-solved-databasecoding-issue/#findComment-334153 Share on other sites More sharing options...
Fadion Posted August 25, 2007 Share Posted August 25, 2007 Ok it is as i initially guessed. What i dont understand is why u use 2 user ids, one hashed in md5 i guess and one normal. As i said in my previous post make the userid primary and auto increment to have unique ids for every user. About the "if user_d2 = 1; do something" it wont work like that, except u want to do that for only some types of ids where u know that admin is 1, moderator is 2 etc. Lets give some examples to expand this: <?php $connect = mysql_connect('host', 'user', 'pass'); mysql_select_db('yourDB'); $query = mysql_query("SELECT * FROM table"); while($values = mysql_fetch_array($query)){ echo "<a href=\"profile.php?id={$values['userid_2']}\">{$values['name']}</a>; } mysql_close($connect); ?> in profile.php <?php $connect = mysql_connect('host', 'user', 'pass'); mysql_select_db('yourDB'); if(isset($_GET['id'])){ $id = mysql_real_escape_string($_GET['id']); $query = mysql_query("SELECT * FROM table WHERE userid_2='$id'"); $values = mysql_fetch_array($query); echo "Name: {$values['name'}"; echo "Email: {$values['email']}"; mysql_close($connect); } ?> The above example is a kinda profile page where all the users are shown with the first code, then when a user is clicked, it brings you to profile.php who has the users data. That may be your case, so u dont have to make one thousands if else statements. Anyway here's what u really wanted: <?php $userid2 = 10; $query = mysql_query("SELECT * FROM table"); while($values = mysql_fetch_array($query)){ if($userid2 = $values['userid_2']){ echo "Name: {$values['name']}"; echo "Email: {$values['email']}"; } } ?> or <?php $userid2 = 10; $query = mysql_query("SELECT * FROM table WHERE usedid_2='$userid2'"); $nrRows = mysql_num_rows($query); if($nrRows == 1){ $values = mysql_fetch_array($query); echo "Name: {$values['name']}"; echo "Email: {$values['email']}"; } ?> Hope this helped. Quote Link to comment https://forums.phpfreaks.com/topic/66692-solved-databasecoding-issue/#findComment-334171 Share on other sites More sharing options...
czukoman20 Posted August 25, 2007 Author Share Posted August 25, 2007 nvm ok i figured it out. now there is only one last thing that u can help me with instead of echoing the text how do i echo an image. Quote Link to comment https://forums.phpfreaks.com/topic/66692-solved-databasecoding-issue/#findComment-334181 Share on other sites More sharing options...
AndyB Posted August 26, 2007 Share Posted August 26, 2007 how do i echo an image. depends how you have named it and where/how you have saved it, but typically it's just basic html ... echo "<img src='happy.gif'>"; Quote Link to comment https://forums.phpfreaks.com/topic/66692-solved-databasecoding-issue/#findComment-334190 Share on other sites More sharing options...
Fadion Posted August 26, 2007 Share Posted August 26, 2007 the error is due to the query. Right now u have "SELECT * FROM table" where table must be the name of table in your database (from the images i can see the table 'users'), so u may have "SELECT * FROM users". Then also change $values['column'] to your actual columns u want to show. From the images u gave i can assamble this code: $userid_2 = 3; $query = mysql_query("SELECT * FROM users WHERE userid_2='$userid_2'"); $values = mysql_fetch_array($query); $nrRows = mysql_num_rows($query); if($nrRows == 1){ echo "Username: " . $values['username'] . "<br />"; echo "User Level: " . $values['userlevel'] . "<br />"; echo "Email: " . $values['email'] . "<br />"; } else{ echo "There is no user with that id"; } What the code do is make a query with mysql_query(), pass the returned values to an array via mysql_fetch_array(), see if there are records which have the userid_2 = 3 and if yes show those values. Does this make any sense now? Quote Link to comment https://forums.phpfreaks.com/topic/66692-solved-databasecoding-issue/#findComment-334193 Share on other sites More sharing options...
Fadion Posted August 26, 2007 Share Posted August 26, 2007 instead of echoing the text how do i echo an image. lol u kept editing your post. AndyB told u. Im making an example of an image got from the database: $query = mysql_query("SELECT * FROM users WHERE userid_2='1'"); $values = mysql_fetch_array($query); echo $values['username'] . "<br />"; echo "<img src=\"images/$values['image']\" />"; Assuming image is a column in your database with the filename of the image. Quote Link to comment https://forums.phpfreaks.com/topic/66692-solved-databasecoding-issue/#findComment-334198 Share on other sites More sharing options...
czukoman20 Posted August 26, 2007 Author Share Posted August 26, 2007 Thankyou all for the help. Quote Link to comment https://forums.phpfreaks.com/topic/66692-solved-databasecoding-issue/#findComment-334200 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.