Jump to content

Recommended Posts

I don't know what code to show you, but I will show what I have so far:

 

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("smrpg", $con);
  
  
//get Sailor Moon's data from the "scout" table
$result = mysql_query("SELECT * FROM scout where identity = 'Sailor Moon'") 
or die(mysql_error());  
$birthdatemonth = $row["birthdatemonth"];
$birthdateday = $row["birthdateday"];
$birthdateyear = $row["birthdateyear"];
$birthdate = $birthdatemonth . "/" . $birthdateday . "/". $birthdateyear;
$identity = $row["identity"];

echo "<h1>This is $identity</h1>";
echo "<table border='0' width='100%'>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td width='25%'>"; 
	echo "<b>Name:</b></td><td>"; 
echo $row['charactername'];
        echo "</td></tr><tr><td>"; 
	echo "<b>Element Of Influence:</b></td><td>";
echo $row['elementofinfluence'];
        echo "</td></tr><tr><td>"; 
	echo "<b>Age:</b></td><td>";
echo $row['age'];
        echo "</td></tr><tr><td>";
    echo "<b>Birthdate:</b></td><td>";
echo $row['$birthdate'];
echo "</td></tr><tr><td>";  
    echo "<b>Height:</b></td><td>"; 
echo $row['height'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Blood Type:</b></td><td>"; 
echo $row['bloodtype'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Hobbies:</b></td><td>"; 
echo $row['hobbies'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Favorite Color:</b></td><td>"; 
echo $row['favoritecolor'];
        echo "</td></tr><tr><td>";   
    echo "<b>Favorite Gemstone:</b></td><td>"; 
echo $row['favoritegemstone'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Favorite Food:</b></td><td>"; 
echo $row['favoritefood'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Least Favorite Food:</b></td><td>"; 
echo $row['leastfavoritefood'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Favorite School Subject:</b></td><td>"; 
echo $row['favoriteschoolsubject'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Least Favorite School Subject:</b></td><td>"; 
echo $row['leastfavoriteschoolsubject'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Strengths:</b></td><td>"; 
echo $row['strengths'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Weaknesses:</b></td><td>"; 
echo $row['weaknesses'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Goal:</b></td><td>"; 
echo $row['goal'];
        echo "</td></tr></table><p>";  
echo $row['biography'];
        echo "</p>"; 
        
echo "</td></tr>"; 
echo "<tr><td> </td></tr>";
} 

echo "</table>";
?>

 

I want to name a variable, and I don't know how to tell in my code that the variable, in this example $identity, will be coming from the table, which is already specified in this code, from the field named "identity". Does this help?

I added that code, "$row = mysql_fetch_array( $result );" but it made everything else on my page disappear except for the $identity variable, which did display properly, but nothign else would display. Why did that happen? What am I doing wrong now?

 

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("smrpg", $con);
  
  
//get Sailor Moon's data from the "scout" table
$result = mysql_query("SELECT * FROM scout where identity = 'Sailor Moon'") 
or die(mysql_error());  
$row = mysql_fetch_array( $result );
$birthdatemonth = $row["birthdatemonth"];
$birthdateday = $row["birthdateday"];
$birthdateyear = $row["birthdateyear"];
$birthdate = $birthdatemonth . "/" . $birthdateday . "/". $birthdateyear;
$identity = $row["identity"];

echo "<h1>$identity</h1>";
echo "<table border='0' width='100%'>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td width='25%'>"; 
	echo "<b>Name:</b></td><td>"; 
echo $row['charactername'];
        echo "</td></tr><tr><td>"; 
	echo "<b>Element Of Influence:</b></td><td>";
echo $row['elementofinfluence'];
        echo "</td></tr><tr><td>"; 
	echo "<b>Age:</b></td><td>";
echo $row['age'];
        echo "</td></tr><tr><td>";
    echo "<b>Birthdate:</b></td><td>";
echo $row['$birthdate'];
echo "</td></tr><tr><td>";  
    echo "<b>Height:</b></td><td>"; 
echo $row['height'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Blood Type:</b></td><td>"; 
echo $row['bloodtype'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Hobbies:</b></td><td>"; 
echo $row['hobbies'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Favorite Color:</b></td><td>"; 
echo $row['favoritecolor'];
        echo "</td></tr><tr><td>";   
    echo "<b>Favorite Gemstone:</b></td><td>"; 
echo $row['favoritegemstone'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Favorite Food:</b></td><td>"; 
echo $row['favoritefood'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Least Favorite Food:</b></td><td>"; 
echo $row['leastfavoritefood'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Favorite School Subject:</b></td><td>"; 
echo $row['favoriteschoolsubject'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Least Favorite School Subject:</b></td><td>"; 
echo $row['leastfavoriteschoolsubject'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Strengths:</b></td><td>"; 
echo $row['strengths'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Weaknesses:</b></td><td>"; 
echo $row['weaknesses'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Goal:</b></td><td>"; 
echo $row['goal'];
        echo "</td></tr></table><p>";  
echo $row['biography'];
        echo "</p>"; 
        
echo "</td></tr>"; 
echo "<tr><td> </td></tr>";
} 

echo "</table>";
?>

id, identity, charactername, elementofinfluence, age, birthdatemonth, birthdateday, birthdateyear, heightfeet, heightinches, bloodtype, hobbies, favoritecolor, favoritegemstone, favoritfood, leastfavoritefood, favoriteschoolsubject, leastfavoriteschoolsubject, strengths, weaknesses, goal, biography

 

Those are all the fields in this particular table.

I am trying to write the code to display one character per page, for a profile, when the viewer clicks a name, but since I wasn't sure exactly how to do it, I was starting with the basics of it, which is just pulling the information from each field, and indicating which character it's for. Does that make sense?

 

So to answer your question, yes, only one character one this page.

//get Sailor Moon's data from the "scout" table
$result = mysql_query("SELECT * FROM scout where identity = 'Sailor Moon'") 
or die(mysql_error());  
$row = mysql_fetch_array( $result );
$birthdatemonth = $row["birthdatemonth"];
$birthdateday = $row["birthdateday"];
$birthdateyear = $row["birthdateyear"];
$birthdate = $birthdatemonth . "/" . $birthdateday . "/". $birthdateyear;
$identity = $row["identity"];

echo "<h1>$identity</h1>";
echo "<table border='0' width='100%'>";
// keeps getting the next row until there are no more to get
echo "<tr><td width='25%'>"; 
	echo "<b>Name:</b></td><td>"; 
echo $row['charactername'];
        echo "</td></tr><tr><td>"; 
	echo "<b>Element Of Influence:</b></td><td>";
echo $row['elementofinfluence'];
        echo "</td></tr><tr><td>"; 
	echo "<b>Age:</b></td><td>";
echo $row['age'];
        echo "</td></tr><tr><td>";
    echo "<b>Birthdate:</b></td><td>";
echo $row['$birthdate'];
echo "</td></tr><tr><td>";  
    echo "<b>Height:</b></td><td>"; 
echo $row['height'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Blood Type:</b></td><td>"; 
echo $row['bloodtype'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Hobbies:</b></td><td>"; 
echo $row['hobbies'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Favorite Color:</b></td><td>"; 
echo $row['favoritecolor'];
        echo "</td></tr><tr><td>";   
    echo "<b>Favorite Gemstone:</b></td><td>"; 
echo $row['favoritegemstone'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Favorite Food:</b></td><td>"; 
echo $row['favoritefood'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Least Favorite Food:</b></td><td>"; 
echo $row['leastfavoritefood'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Favorite School Subject:</b></td><td>"; 
echo $row['favoriteschoolsubject'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Least Favorite School Subject:</b></td><td>"; 
echo $row['leastfavoriteschoolsubject'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Strengths:</b></td><td>"; 
echo $row['strengths'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Weaknesses:</b></td><td>"; 
echo $row['weaknesses'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Goal:</b></td><td>"; 
echo $row['goal'];
        echo "</td></tr></table><p>";  
echo $row['biography'];
        echo "</p>"; 
        
echo "</td></tr>"; 
echo "<tr><td> </td></tr>";

echo "</table>";

 

You were calling mysql_fetch_array() twice. One is enough for one row, and the second time it was called, it got empty row.

Well, most of the page displays correctly, including $identity, but the $birthday still won't display for some reason. What am I doing wrong? I tried uploading it to my server to show you, but nothing shows up for some reason. Sorry. I will have to look at it again tomorrow/later today.

I figured you're must be having a hard night :P

 

Paste your code after the changes, so that we can work on current version ;)

 

 

As for birthdate:

 

echo "<b>Birthdate:</b></td><td>";
echo $row['$birthdate'];            // <--- birthdate is in $birthdate not in $row['birthdate'] 
echo "</td></tr><tr><td>";  

Okay, now it's right. LOL I kept missing things for some reason. Thank you so much for helping me with that! Now, Do you know how I can write it so that it displays is at the month name instead of the number? Like June instead of 06? Is it possible to set it up to do that, even though it is 06 in my database? I'm guessing there's a way, but I'm not sure how exactly.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.