Taisira Posted February 28, 2009 Share Posted February 28, 2009 EDIT: I had edited out personal information, so some of the code isn't accurate. I know the title isn't very descriptive, but I'm not sure how to sum this up. I'm creating a character database website, which stores information such as names, factions, personality, etc. I have already created the forms, and the form handler, it can successfully enter the data into the correct columns and such. Here's my problem: I know how to call the data into a table, however, because there is so much of it, I only wanted to display three of the columns on that page. I know it's possible to make it so when a user clicks on a character's name it will display all of that character's information, and only that character's information, but for the life of me I can't figure out how it's done. I've been studying an address book that does something very similar, and I've done hours of searching, but I'm still lost. Here's the code I have currently for the display page. <html> <head> <title>View Guardians Characters</title> <link href="style.css" type="text/css" rel="stylesheet" /> </head> <body> <?php //(connect to database here) mysql_connect("hostnamehere",$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM Guardians ORDER BY faction"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table border="0" cellspacing="2" cellpadding="2"> <tr> <th>First Name</th> <th>Race</th> <th>Faction</th> </tr> <?php $i=0; while ($i < $num) { $name=mysql_result($result,$i,"name_first"); $race=mysql_result($result,$i,"race"); $faction=mysql_result($result,$i,"faction"); ?> <tr> <td><?php echo $name; ?></td> <td><?php echo $race; ?></td> <td><?php echo $faction; ?></td> </tr> <?php $i++; } ?> </body> </html> Help would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/147278-solved-displaying-partial-rows-together-complete-row-individually/ Share on other sites More sharing options...
mjahkoh Posted February 28, 2009 Share Posted February 28, 2009 This how its done. Pass the id concerning that guy only but u need to create functions as below. That all as below Under "$num=mysql_numrows($result);" put this function PersonalInfo($username){ /*SELECT CASE property.propertytype WHEN 1 THEN 'Apartment' WHEN 2 THEN 'House' ELSE 'House' END as type,property.propertytype,constituency.constituency, property.property_hd_id,property.constituency_hd_id,property.area_hd_id,property.noofrooms,property.electricity,property.goodroads,property.playground,property.privacy,property.security,property.internaltoilets,property.water,property.facilities,property.rent,property.terms,CASE property.leaser WHEN 1 THEN 'Broker' WHEN 2 THEN 'Family Member' WHEN 3 THEN 'Goverment Agencies' WHEN 4 THEN 'Lawyer' ELSE 'Owner' END as leaser,property.name,property.users_hd_id,property.parking , area.area,property.picture1url,property.picture2url,property.picture3url,login.username FROM property Inner Join constituency ON property.constituency_hd_id = constituency.constituency_hd_id Inner Join area ON property.area_hd_id = area.area_hd_id Inner Join login ON login.users_hd_id = property.users_hd_id WHERE property.property_hd_id = 112 and login.username = 'mjahkoh' */ $query="SELECT * from login where username ='". $username ."'"; //echo $query .'<br>'; $result = mysql_query($query); /* Error occurred, return given name by default */ if(!$result || (mysql_numrows($result) < 1)){ return NULL; } /* Return result array */ $dbarray = mysql_fetch_array($result); return $dbarray; } /*-------------------------------------------------------*/ in the body of the html use this to call the function and retrieve values $Info = PersonalInfo("username"); echo $Info ['name']; //name is a field in the database Quote Link to comment https://forums.phpfreaks.com/topic/147278-solved-displaying-partial-rows-together-complete-row-individually/#findComment-773129 Share on other sites More sharing options...
Taisira Posted February 28, 2009 Author Share Posted February 28, 2009 I'm really sorry to bug, but I implemented that code and (after fixing a connection error) the code isn't behaving as intended. I believe that your code works, but I think I misinterpreted how to call it. Or perhaps I didn't explain well enough what I wanted. Could you please explain where I would need to call the function to open the character's information (I think it has to open in a seperate page to work correctly)? Also are echo $Info ['name']; and SELECT * from login the only things I have to edit to match my needs? Last thing, I'm using $username to connect to my database, does that not interfere with this code or should I change the variable? I'm sorry; I'm not very good at interpreting others' code. But thank you very much for taking the time to help me out. Quote Link to comment https://forums.phpfreaks.com/topic/147278-solved-displaying-partial-rows-together-complete-row-individually/#findComment-773252 Share on other sites More sharing options...
premiso Posted February 28, 2009 Share Posted February 28, 2009 So you want it to when a user clicks it displays that characters information. This is rather easy, you need to store the rest of the information in a hidden div (style="display:none") or use AJAX to retrieve that information. I would go just the hidden div route. You may want to look into "Shadow Box" javascript code, as that maybe just what you are looking for. You need to use html/css to get this to work. Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/147278-solved-displaying-partial-rows-together-complete-row-individually/#findComment-773253 Share on other sites More sharing options...
Taisira Posted February 28, 2009 Author Share Posted February 28, 2009 I'll check it out. I hope that works. I thought it wouldn't be possible to do that kind of thing with a shadow box, as I have used them before, since it is not fixed information. It makes sense from a programmer's standpoint; I guess I'll need to mess around with it more. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/147278-solved-displaying-partial-rows-together-complete-row-individually/#findComment-773383 Share on other sites More sharing options...
Taisira Posted February 28, 2009 Author Share Posted February 28, 2009 I'm sorry, and I feel so stupid. I get it now. Jeez, I can't believe I couldn't wrap my head around it. The answer was staring at me in the face all this time. Sorry to waste your time. Quote Link to comment https://forums.phpfreaks.com/topic/147278-solved-displaying-partial-rows-together-complete-row-individually/#findComment-773423 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.