Pass multiple variables through link (reads only one) - php

I'm trying to pass some variables from a link but for some reason it only reads one of them. Below is the link and the code. roundNo shows up fine.
archery/viewround.php?gameNo=1&roundNo=7
echo $_GET['gameNo'];
echo $_GET['roundNo'];
echo "<table border><tr><th>Round ID</th><th>Match Name</th><th>Player Name</th><th>Shot 1</th><th>Shot 2</th><th>Shot 3</th><th>Shot 4</th><th>Shot 5</th><th>Shot 6</th><th>Shot 7</th><th>Shot 8</th><th>Shot 9</th><th>Shot 10</th></tr>";
while ($row = mysql_fetch_array($sql)) {
$tempPlayerName = getnamewithid($row["player_id"]);
$tempMatchName = getmatchnamewithid($_GET['gameNo']);
echo "<tr>";
echo '<td>' . $row["round_id"].'</td>';
echo "<td>" . $tempMatchName. "</td>";
echo "<td>" . $tempPlayerName. "</td>";
echo "<td>" . $row["shot_1"] . "</td>";
echo "<td>" . $row["shot_2"] . "</td>";
echo "<td>" . $row["shot_3"] . "</td>";
echo "<td>" . $row["shot_4"] . "</td>";
echo "<td>" . $row["shot_5"] . "</td>";
echo "<td>" . $row["shot_6"] . "</td>";
echo "<td>" . $row["shot_7"] . "</td>";
echo "<td>" . $row["shot_8"] . "</td>";
echo "<td>" . $row["shot_9"] . "</td>";
echo "<td>" . $row["shot_10"] . "</td>";
echo "</tr>";
$i++;
}
echo "</table>";

Related

How should I change the cell color according to a specific price?

I want to change the color of the entire cell according to a specific value. But what should I do when the grammar is wrong and it doesn't work?
in this my code
echo "<tr if( $row['treatment_fees_check_division'] == 'error') : style='yellow' >";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['chart_num'] . "</td>";
echo "<td>" . $row['chart_name'] . "</td>";
echo "<td>" . substr($row['visit'], 0,10) . "</td>";
echo "<td >" . number_format($row['total_medical_bills']) . "</td>";
echo "<td >" . number_format($row['total_amount']) . "</td>";
echo "<td>" . number_format($row['amount_asked']) . "</td>";
echo "<td>" . number_format($row['medical_bills_payment']) . "</td>";
echo "<td>" . number_format($row['personal_liability_amount']) . "</td>";
echo "<td >" . number_format($row['non_payment']) . "</td>";
echo "<td >" . number_format($row['non_payment_sales']) . "</td>";
echo "<td>" . $row['insurance_division'] . "</td>";
echo "<td>" . $row['division'] . "</td>";
echo "<td>" . number_format($row['cash_amount_received']) . "</td>";
echo "<td>" . number_format($row['cash_receipt']) . "</td>";
echo "<td>" . number_format($row['cash_receipt_non_payment']) . "</td>";
echo "<td>" . number_format($row['cash_receipt_payment']) . "</td>";
echo "<td>" . number_format($row['card_amount_received']) . "</td>";
echo "<td>" . number_format($row['card_non_payment']) . "</td>";
echo "<td>" . number_format($row['card_payment']) . "</td>";
echo "<td>" . number_format($row['treatment_fees_difference']) . "</td>";
echo "<td>" . $row['treatment_fees_check_division'] . "</td>";
echo "</tr>";
Try replacing your first line with something like this.
if ($row['treatment_fees_check_division'] == 'error') {
echo "<tr style='yellow' >";
} else {
echo "<tr >";
}

HTML table is adding additional row when calling information from database table

I seem to be having an issue with my HTML formatting. I am calling the database to display all information within the table on a webpage. I have got the information coming down into the table. Unfortunately the table is adding an additional row to the bottom of the table making 4 rows when in fact there is only 3 rows displaying in the database.
Any idea as to why?
<?php
//connect to the server
$link = mysql_connect('*****', '*****', '****');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('******');
$query = mysql_query("SELECT * FROM tablename");
echo "<table border='1'>
<tr>
<td>Date</td>
<td>Region</td>
<td>Cameraman</td>
<td>Livestream?</td>
<td>Event Title</td>
<td>Lecturer</td>
<td>Time</td>
<td>Speaker</td>
<td>ICE Contact</td>
<td>Venue Address</td>
<td>Venue Contact</td>
<td>Additional Comments</td>
<td>On App?</td>
</tr>";
WHILE($rows = mysql_fetch_array($query)):
echo "<tr>";
echo "<td>" . $rows['date'] . "</td>";
echo "<td>" . $rows['region'] . "</td>";
echo "<td>" . $rows['cameraman'] . "</td>";
echo "<td>" . $rows['livestream'] . "</td>";
echo "<td>" . $rows['eventitle'] . "</td>";
echo "<td>" . $rows['lecturer'] . "</td>";
echo "<td>" . $rows['time'] . "</td>";
echo "<td>" . $rows['speaker'] . "</td>";
echo "<td>" . $rows['icecontact'] . "</td>";
echo "<td>" . $rows['venueaddress'] . "</td>";
echo "<td>" . $rows['venuecontact'] . "</td>";
echo "<td>" . $rows['additioncomments'] . "</td>";
echo "<td>" . $rows['onapp'] . "</td>";
echo "</tr>";
endwhile;
echo "</table>";
?>
I have added the link to the page below.
http://cpdonline.tv/spreadsheet/spreadsheet.php
Update your while loop with the following:
WHILE($rows = mysql_fetch_array($query)):
$rows = array_filter($rows);
if (!empty($rows)) {
echo "<tr>";
echo "<td>" . $rows['date'] . "</td>";
echo "<td>" . $rows['region'] . "</td>";
echo "<td>" . $rows['cameraman'] . "</td>";
echo "<td>" . $rows['livestream'] . "</td>";
echo "<td>" . $rows['eventitle'] . "</td>";
echo "<td>" . $rows['lecturer'] . "</td>";
echo "<td>" . $rows['time'] . "</td>";
echo "<td>" . $rows['speaker'] . "</td>";
echo "<td>" . $rows['icecontact'] . "</td>";
echo "<td>" . $rows['venueaddress'] . "</td>";
echo "<td>" . $rows['venuecontact'] . "</td>";
echo "<td>" . $rows['additioncomments'] . "</td>";
echo "<td>" . $rows['onapp'] . "</td>";
echo "</tr>";
}
endwhile;
echo "</table>";
array_filter() function's default behavior will remove all values from array which are equal to null, 0, '' or false.
It seems that you have empty data in your database, as many lines are empty
Check your database for empty records or run the query
DELETE FROM table_name WHERE column='';

Adding autonumber column to php table that reads from mysql

I am trying to add a column before my first column that starts numbering each record, starting from 1. I was trying to add autoincrement to this line echo "" . $row['ss'] . "";, but that does not seem to want to work. Any ideas how to do this?
My code looks like this:
$result = mysqli_query($con,"SELECT * FROM `results` WHERE Event='100' AND Gender='M' ORDER BY Performance ASC");
echo "<table border='0'>
<tr>
<th align='left'>Pos</th>
<th align='left'>Event</th>
<th>Performance</th>
<th>Wind</th>
<th>Place</th>
<th align='left'>Name</th>
<th align='left'>Surname</th>
<th>Age</th>
<th>Team</th>
<th>Meet</th>
<th>Date</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ss'] . "</td>";
echo "<td>" . $row['Event'] . "</td>";
echo "<td>" . $row['Performance'] . "</td>";
echo "<td>" . $row['Wind'] . "</td>";
echo "<td>" . $row['Pos'] . "</td>";
echo "<td width='100' align='left'>" . $row['Surname'] . "</td>";
echo "<td Width='100'>" . $row['Name'] . "</td>";
echo "<td>" . $row['Age'] . "</td>";
echo "<td>" . $row['Team'] . "</td>";
echo "<td>" . $row['Meet'] . "</td>";
echo "<td>" . $row['Date'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Add this line in header
<th align='left'>#</th>
And here php code
$count = 1;
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $count . "</td>";
echo "<td>" . $row['ss'] . "</td>";
echo "<td>" . $row['Event'] . "</td>";
echo "<td>" . $row['Performance'] . "</td>";
echo "<td>" . $row['Wind'] . "</td>";
echo "<td>" . $row['Pos'] . "</td>";
echo "<td width='100' align='left'>" . $row['Surname'] . "</td>";
echo "<td Width='100'>" . $row['Name'] . "</td>";
echo "<td>" . $row['Age'] . "</td>";
echo "<td>" . $row['Team'] . "</td>";
echo "<td>" . $row['Meet'] . "</td>";
echo "<td>" . $row['Date'] . "</td>";
echo "</tr>";
//other code
$count=$count+1;
}
A better solution would be to use a variable counter to "number" your rows:
$counter = 1;
while($row = mysqli_fetch_array($result))
echo "<td>" . $counter . "</td>";
$counter++;
}
This is the right way to do it since if that ss column is the mysql auto increment, then your rows will not be numbered by the SORT but rather from the order in which they were inserted into the database regardless of any sorting you apply.
Try to change fetch_array with fetch_assoc

MySQL Query Returns Blank Field with AES_ENCRYPT

My query string is $SQLstring = "SELECT name, address, city, state, zip, homephone, cellphone, position, shift, status, workedherebefore, previousemploymentdate, referred, empname, under18, friends, empname2, currentlyemployed, contactemployer, lawful, worktime, workweekends, dateavailable, desiredsalary, position1, from1, to1, duties1, company1, cophone1, startsalary, endsalary, reasonleaving1, supervisor1, contact1, position2, from2, to2, duties2, company2, cophone2, startsalary2,
endsalary2, reasonleaving2, supervisor2, contact2, position3, from3, to3, duties3, company3, cophone3, startsalary3, endsalary3, reasonleaving3, supervisor3, contact3, comments, training, otherqual, documents, dltype, dlstate, expdate, yearsdriving, movingviolations, hsname, hscity, hsstate, hsdates, collegename, collegecity, collegestate, collegedates, othername, othercity, otherstate, otherdates, licenseorcert, refname1, refbusiness1, reftitle1, refaddress1, refphone1, refname2, refbusiness2, reftitle2, refaddress2, refphone2, refname3, refbusiness3, reftitle3, refaddress3, refphone3,felony, iffelony, fired, iffired, resident, explanation, signed, q1, q2, q3, q4, mq1, mq2, mq3, mq4, mq5, mq6, mq7, mq8, mq9, mq10, mq11, mq12, mq13, mq14, mq15, mq16,
mq17, mq18, mq19, mq20, mq21, mq22, mq23, mq24, mq24b, mq25, mq25b, mq26, mq27a, mq27b, mq27c, mq28, mq29, mq30answer, disclosuresig, verify_name, other_names, dob, AES_DECRYPT(ssn,'$key') AS ssn FROM applications";
I query the results and then return them in a table. All of them work except for the AES_DECRYPT field (ssn). In the database it seems to have been encrypted fine, but this field in the query is returned as blank. Here is the rest of the code, just in case it's relevant:
$key="88b871WZ3SntWK67rN3l2J1SvMqsOjyk";
$QueryResult = #mysql_query($SQLstring, $conn) or die("Query Problem - "
. mysql_error($conn) . " - Error Number - "
. mysql_errno($conn));
$num_result = mysql_num_rows($QueryResult);
echo "<table>";
for ($i = 0; $i < $num_result; $i++)
{
$row = mysql_fetch_array($QueryResult);
echo "<tr>";
echo "<td>" . $row["name"] . "</td>";
echo "<td>" . $row["email"] . "</td>";
echo "<td>" . $row["address"] . "</td>";
echo "<td>" . $row["city"] . "</td>";
echo "<td>" . $row["state"] . "</td>";
echo "<td>" . $row["zip"] . "</td>";
echo "<td>" . $row["homephone"] . "</td>";
echo "<td>" . $row["cellphone"] . "</td>";
echo "<td>" . $row["position"] . "</td>";
echo "<td>" . $row["shift"] . "</td>";
echo "<td>" . $row["status"] . "</td>";
echo "<td>" . $row["workedherebefore"] . "</td>";
echo "<td>" . $row["previousemploymentdate"] . "</td>";
echo "<td>" . $row["referred"] . "</td>";
echo "<td>" . $row["empname"] . "</td>";
echo "<td>" . $row["under18"] . "</td>";
echo "<td>" . $row["friends"] . "</td>";
echo "<td>" . $row["empname2"] . "</td>";
echo "<td>" . $row["currentlyemployed"] . "</td>";
echo "<td>" . $row["contactemployer"] . "</td>";
echo "<td>" . $row["lawful"] . "</td>";
echo "<td>" . $row["worktime"] . "</td>";
echo "<td>" . $row["workweekends"] . "</td>";
echo "<td>" . $row["dateavailable"] . "</td>";
echo "<td>" . $row["desiredsalary"] . "</td>";
echo "<td>" . $row["position1"] . "</td>";
echo "<td>" . $row["from1"] . "</td>";
echo "<td>" . $row["to1"] . "</td>";
echo "<td>" . $row["duties1"] . "</td>";
echo "<td>" . $row["company1"] . "</td>";
echo "<td>" . $row["cophone1"] . "</td>";
echo "<td>" . $row["startsalary"] . "</td>";
echo "<td>" . $row["endsalary"] . "</td>";
echo "<td>" . $row["reasonleaving1"] . "</td>";
echo "<td>" . $row["supervisor1"] . "</td>";
echo "<td>" . $row["contact1"] . "</td>";
echo "<td>" . $row["position2"] . "</td>";
echo "<td>" . $row["from2"] . "</td>";
echo "<td>" . $row["to2"] . "</td>";
echo "<td>" . $row["duties2"] . "</td>";
echo "<td>" . $row["company2"] . "</td>";
echo "<td>" . $row["cophone2"] . "</td>";
echo "<td>" . $row["startsalary2"] . "</td>";
echo "<td>" . $row["endsalary2"] . "</td>";
echo "<td>" . $row["reasonleaving2"] . "</td>";
echo "<td>" . $row["supervisor2"] . "</td>";
echo "<td>" . $row["contact2"] . "</td>";
echo "<td>" . $row["position3"] . "</td>";
echo "<td>" . $row["from3"] . "</td>";
echo "<td>" . $row["to3"] . "</td>";
echo "<td>" . $row["duties3"] . "</td>";
echo "<td>" . $row["company3"] . "</td>";
echo "<td>" . $row["cophone3"] . "</td>";
echo "<td>" . $row["startsalary3"] . "</td>";
echo "<td>" . $row["endsalary3"] . "</td>";
echo "<td>" . $row["reasonleaving3"] . "</td>";
echo "<td>" . $row["supervisor3"] . "</td>";
echo "<td>" . $row["contact3"] . "</td>";
echo "<td>" . $row["comments"] . "</td>";
echo "<td>" . $row["training"] . "</td>";
echo "<td>" . $row["otherqual"] . "</td>";
echo "<td>" . $row["documents"] . "</td>";
echo "<td>" . $row["dltype"] . "</td>";
echo "<td>" . $row["dlstate"] . "</td>";
echo "<td>" . $row["expdate"] . "</td>";
echo "<td>" . $row["yearsdriving"] . "</td>";
echo "<td>" . $row["movingviolations"] . "</td>";
echo "<td>" . $row["hsname"] . "</td>";
echo "<td>" . $row["hscity"] . "</td>";
echo "<td>" . $row["hsstate"] . "</td>";
echo "<td>" . $row["hsdates"] . "</td>";
echo "<td>" . $row["collegename"] . "</td>";
echo "<td>" . $row["collegecity"] . "</td>";
echo "<td>" . $row["collegestate"] . "</td>";
echo "<td>" . $row["collegedates"] . "</td>";
echo "<td>" . $row["othername"] . "</td>";
echo "<td>" . $row["othercity"] . "</td>";
echo "<td>" . $row["otherstate"] . "</td>";
echo "<td>" . $row["otherdates"] . "</td>";
echo "<td>" . $row["licenseorcert"] . "</td>";
echo "<td>" . $row["refname1"] . "</td>";
echo "<td>" . $row["refbusiness1"] . "</td>";
echo "<td>" . $row["reftitle1"] . "</td>";
echo "<td>" . $row["refaddress1"] . "</td>";
echo "<td>" . $row["refphone1"] . "</td>";
echo "<td>" . $row["refname2"] . "</td>";
echo "<td>" . $row["refbusiness2"] . "</td>";
echo "<td>" . $row["reftitle2"] . "</td>";
echo "<td>" . $row["refaddress2"] . "</td>";
echo "<td>" . $row["refphone2"] . "</td>";
echo "<td>" . $row["refname3"] . "</td>";
echo "<td>" . $row["refbusiness3"] . "</td>";
echo "<td>" . $row["reftitle3"] . "</td>";
echo "<td>" . $row["refaddress3"] . "</td>";
echo "<td>" . $row["refphone3,felony"] . "</td>";
echo "<td>" . $row["iffelony"] . "</td>";
echo "<td>" . $row["fired"] . "</td>";
echo "<td>" . $row["iffired"] . "</td>";
echo "<td>" . $row["resident"] . "</td>";
echo "<td>" . $row["explanation"] . "</td>";
echo "<td>" . $row["signed"] . "</td>";
echo "<td>" . $row["q1"] . "</td>";
echo "<td>" . $row["q2"] . "</td>";
echo "<td>" . $row["q3"] . "</td>";
echo "<td>" . $row["q4"] . "</td>";
echo "<td>" . $row["mq1"] . "</td>";
echo "<td>" . $row["mq2"] . "</td>";
echo "<td>" . $row["mq3"] . "</td>";
echo "<td>" . $row["mq4"] . "</td>";
echo "<td>" . $row["mq5"] . "</td>";
echo "<td>" . $row["mq6"] . "</td>";
echo "<td>" . $row["mq7"] . "</td>";
echo "<td>" . $row["mq8"] . "</td>";
echo "<td>" . $row["mq9"] . "</td>";
echo "<td>" . $row["mq10"] . "</td>";
echo "<td>" . $row["mq11"] . "</td>";
echo "<td>" . $row["mq12"] . "</td>";
echo "<td>" . $row["mq13"] . "</td>";
echo "<td>" . $row["mq14"] . "</td>";
echo "<td>" . $row["mq15"] . "</td>";
echo "<td>" . $row["mq16"] . "</td>";
echo "<td>" . $row["mq17"] . "</td>";
echo "<td>" . $row["mq18"] . "</td>";
echo "<td>" . $row["mq19"] . "</td>";
echo "<td>" . $row["mq20"] . "</td>";
echo "<td>" . $row["mq21"] . "</td>";
echo "<td>" . $row["mq22"] . "</td>";
echo "<td>" . $row["mq23"] . "</td>";
echo "<td>" . $row["mq24"] . "</td>";
echo "<td>" . $row["mq24b"] . "</td>";
echo "<td>" . $row["mq25"] . "</td>";
echo "<td>" . $row["mq25b"] . "</td>";
echo "<td>" . $row["mq26"] . "</td>";
echo "<td>" . $row["mq27a"] . "</td>";
echo "<td>" . $row["mq27b"] . "</td>";
echo "<td>" . $row["mq27c"] . "</td>";
echo "<td>" . $row["mq28"] . "</td>";
echo "<td>" . $row["mq29"] . "</td>";
echo "<td>" . $row["mq30answer"] . "</td>";
echo "<td>" . $row["disclosuresig"] . "</td>";
echo "<td>" . $row["verify_name"] . "</td>";
echo "<td>" . $row["other_names"] . "</td>";
echo "<td>" . $row['ssn'] . "</td>";
echo "<td>" . $row["dob"] . "</td>";
echo "</tr>";
}
echo "</table>";
}
To use AES_ENCRYPT and AES_DECRYPT the field type must be BLOB. I had it set to VARCHAR and it wasn't recognizing some of the characters. Changing the field type to blob worked perfectly.
MySQL AES_DECRYPT() returns NULL if detects invalid data.
So the strings passed to the AES_DECRYPT() are invalid.
In this type of cases, I recommend to ECHO/alert the query so that you can see everything is right. The most probable mistake is what AD7six noted... the $key is probably empty.
$key="88b871WZ3SntWK67rN3l2J1SvMqsOjyk";
$SQLstring = "SELECT * FROM table"; // Replace with your Query
echo $SQLstring;
$QueryResult = #mysql_query($SQLstring, $conn) or die("Query Problem - " . mysql_error($conn) . " - Error Number - " . mysql_errno($conn));
Alerter:
echo "<script type='text/javascript'>
alert($SQLstring);
</script>";
I also recommend you read about mysqli

I need to assign a unqiue class to a PHP MYSQL table's TR

How can I assign a class id that is unique for all the <tr>
The id's need to stay stay even when I refresh as I will be using them to style the table.
Here is the code I am using:
while($row = mysql_fetch_array($result2))
{
echo "<tr id='centered' class='"; echo "'";
echo "<td>" . $row['Year_9'] . "</td>";
echo "<td>" . $row['Year_8'] . "</td>";
echo "<td>" . $row['Year_7'] . "</td>";
echo "<td>" . $row['Year_6'] . "</td>";
echo "<td>" . $row['Year_5'] . "</td>";
echo "<td>" . $row['Year_4'] . "</td>";
echo "<td>" . $row['Year_3'] . "</td>";
echo "<td>" . $row['Year_2'] . "</td>";
echo "<td>" . $row['Year_1'] . "</td>";
echo "<td>" . $row['Year_0'] . "</td>";
Perhaps use a counter with a multi-valued class?
$i = 1;
while($row = mysql_fetch_array($result2))
{
$secondClass = 'abc' + $i;
echo "<tr id='centered' class='firstClass $secondClass'>";
...
$i++;
}

Categories