Sevian Posted August 9, 2010 Share Posted August 9, 2010 Hey, I am still learning PHP and all it's functions. So some of the coding may not be clean. But here is the script I made that I am having problems with: <?php // Adjust MySQL connection settings... $username="newestfu_Dan"; $password = "camaro"; $hostname = "localhost"; $database = "newestfu_wowtrader"; // Connect to MySQL... $conn = mysql_connect($hostname, $username, $password) or die("Connecting to MySQL failed"); mysql_select_db($database, $conn) or die("Selecting MySQL database failed"); // Run our query, see if session username exists in session field... $sql="select username,email from user where username='{$_SESSION['user']}' limit 1"; $result=mysql_query($sql,$conn); // Parse our results into $data (as an associative array)... $data=mysql_fetch_assoc($result); // If one row was found in the result set, username exists... if (mysql_num_rows($result)==1) { print "Welcome, {$data['username']}, your current email on file is: {$data['email']}"; echo "<br />"; $query="select seller,id,title from listings"; $queryresult=mysql_query($query,$conn); $info=mysql_fetch_assoc($queryresult); if ( $info['seller'] == $data['username'] ) { echo "{$info['title']}"; } else { echo "You have no current auctions"; } // Otherwise... } else { print "Sorry, the username {$_SESSION['username']} was not found in our database..."; } ?> </body> </html> There are two queries going on. The first selects from the table "user" and gets the username depending on the user session and email. If one exists, it will go onto the next query to select from the table "listings" and gets seller, title, and id. It will then check if the username is equal to the seller. If it is, it will display the title. If not it displays otherwise. The problem is if the user has more than one title listed. But only 1 shows up. I'm guessing the line that has to change is echo "{$info['title']}"; But I'm not to sure on what to change it to. Thanks all for your help! Quote Link to comment Share on other sites More sharing options...
xangelo Posted August 9, 2010 Share Posted August 9, 2010 Actually the problem is here: $info=mysql_fetch_assoc($queryresult); Replace everything from $query to //otherwise with the following. $query='select seller,id,title from listings where seller = "'.$data['username'].'"'; $queryresult=mysql_query($query,$conn); while($info = mysql_fetch_assoc($queryresult)){ echo "{$info['title']}"; } Quote Link to comment Share on other sites More sharing options...
Sevian Posted August 9, 2010 Author Share Posted August 9, 2010 Awesome! But that ran me into another problem that I didn't think about. Where could a break be incorporated to where each one appears on a new line so it doesn't look jumbled together? Quote Link to comment Share on other sites More sharing options...
xangelo Posted August 9, 2010 Share Posted August 9, 2010 echo $info['title'].'<br>'; However, might I suggest looking into tables to organize the displayed data? http://w3schools.com/html/html_tables.asp Quote Link to comment Share on other sites More sharing options...
Sevian Posted August 9, 2010 Author Share Posted August 9, 2010 Thank you for all your help, that link has been bookmarked! 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.