Hey guys, I'm working on a website with PHP and MYSQL with my roommate, and am running into several snags. I was wondering if any of you would be able to help. Here is the situation:
this is a roster page I'm making. every person in my band at the beginning of the year has an index card that they write their information on. I'm trying to replicate that on this page. each person has an index card, the information is outputted on it. the roster is going to do the same thing. the idea is to click on a link in the (horizontal) scrolling box and it will refresh the information on the card
the information on the card is a set of global variables. all of them are session data that is fetched from the database when the user logs in. even though this is frowned upon usually, its the best way to do it in this scenario, because of the amount of times the info is being used on the site.
so far, my roster program fetches the usernames from the database, and displays them with an image above it, as it should. I"m running into a few snags:
the link to each person is going to have to query the database with their information. after the query, I can get the information from the database, update the variables in an array and then assign those global variables new values to be outputted on the page on the index card.
I've made the function below do just that. its at the bottom of this page. it gets the information from the database, stores it in an array, and I *think* assigns all of them values. it then *should* update the global variables and refresh only that part of the screen.
the link as you can see is a call to the function, it sends the global variable "$username" to the function. the function then takes $username, stores it in $received_username, and passes it to the SQL query. everything should then update. Am I doing this wrong?
I may be having a problem with the scope of the variables in the function, even though they are global variables, I'm not sure if the function recognizes them as such. what do you think?
The program used to return the usernames as links in the loop, which gave me hope. It is no longer doing that and I don't know what I did to mess it up.
Anyway, this is my situation. Any ideas?
$get_username_query = "SELECT username FROM UCMB_Table";
$result_get_username_query = mysql_query($get_username_query, $connection)
or die ("And the dragon comes in the niIIIIght!.. i mean... Unable to execute get_username_query");
$number_of_rows = mysql_num_rows($result_get_username_query);
$width_of_inline_table = (150 * $number_of_rows) + (20 * ($number_of_rows - 1)) + (8.75 * ($number_of_rows - 1));
$width_of_inline_table .= "px";
/* ============== SELECT QUERY FOR PEOPLES ROSTER CARDS ============== */
if ($log_out != yes) /* LOGGED IN */
{
echo"<b>Name:</b> $first_name $last_name <b>Instrument:</b> $primary_instrument
<b>Class:</b> $class_standing <b>Address:</b> $city, $state <b>Phone:</b> $cell_phone
<b>Major:</b> $intended_major <b>Address on Campus:</b> $campus_address
<div class='edit_profile text_center double_break single_break_top'>
<p>
<div class='edit_profile_links'>
<ul>
<li>$first_name $last_name</li>
<li>$primary_instrument</li>
<li>$class_standing</li>
<li>$city, $state</li>
<li>$intended_major</li>
<li>$campus_address</li>
<li>$cell_phone</li>
</ul>
</div>
</p>
</div>
<div class='iframe_css'>
<p style='width: $width_of_inline_table;'>";
if ($number_of_rows == 0)
{
echo "Your search returned no results; please try another search.";
}
else
{
while ($username_array = mysql_fetch_assoc($result_get_username_query))
{
extract($username_array);
$number_of_rows--;
if ($number_of_rows != '0')
{
echo"
<span class='span_block text_center' style='float: left; margin-right: 20px;'>
<img src='../schedule_of_events_index-t.jpg' width='150' height='74' alt='' title='' style='margin: 0 0 5px;' />
<a href='";input_username($username);echo"' title=''>$username</a>
</span>
";
}
Here is the function for the code above:
function input_username($received_username)
{
//Initialize MySQL variables
blah blah blah
//Open MySQL connecion
$connection = mysql_connect($host, $user, $mysql_password)
or die ("Stupid Crap for Crap...Could not connect to the server");
//Open MySQL database
$db = mysql_select_db($databasename, $connection)
or die ("Crapfully Yours, Unable to select the database");
$get_index_card_query = "SELECT first_name, last_name, email_address, aim_screenname, cell_phone, campus_phone, campus_address, class_standing, intended_major, date_of_birth, home_phone, city, state, high_school, primary_instrument FROM UCMB_Table WHERE username LIKE "$received_username%"";
$result_get_index_card_query = mysql_query($get_index_card_query, $connection)
or die ("And the dragon comes in the niIIIIght!.. i mean... Unable to execute result_get_index_card_query");
$index_card_array = mysql_fetch_array($result_get_index_card_query);
// Assign Values To Global Variables
$first_name = $index_card_array['first_name'];
$last_name = $index_card_array['last_name'];
$email_address = $index_card_array['email_address'];
$aim_screenname = $index_card_array['aim_screenname'];
$cell_phone = $index_card_array['cell_phone'];
$campus_phone = $index_card_array['campus_phone'];
$campus_address = $index_card_array['campus_address'];
$class_standing = $index_card_array['class_standing'];
$intended_major = $index_card_array['intended_major'];
$date_of_birth = $index_card_array['date_of_birth'];
$home_phone = $index_card_array['home_phone'];
$city = $index_card_array['city'];
$state = $index_card_array['state'];
$high_school = $index_card_array['high_school'];
$primary_instrument = $index_card_array['primary_instrument'];
// Close MySQL Connection
mysql_close($connection);
return;
}
Aqua-Soft Forums