Sorry, newbie question I know, however I’ve currently got mySQL results only showing when using the echo command through PHP etc..
Now, I am able to source the information fine, however I would like the result of a query to show up in a form e.g.
Rather than :-
$loggedinuser = $session->username;
//$query = "SELECT surname, firstname FROM PASSENGER WHERE username = '$jared'";
$query2 = "SELECT p.surname, f.destination FROM PASSENGER p, FLIGHT_INFO f WHERE p.username = '$loggedinuser' AND p.flightNo = f.flightNo";
$result = mysql_query($query2);
while($row = mysql_fetch_array($result))
{
echo $row['surname'] ." ". $row['destination'];
}
echo mysql_error();
I would like to print the SQL result in a HTML form…e.g. one that follows the convention of:-
Surname: <input type="text" name="firstname" value="echo $row['surname']/>
If you see where I am coming from. Is this really bad practice using forms to display mySQL results, or can it be done? If not really, what ways would you recommend I print the data? In a table of some sort, but how can I then use fields?
Regards,
Tom.
Something like this work:-
<?php
$loggedinuser = $session->username;
//$query = "SELECT surname, firstname FROM PASSENGER WHERE username = '$jared'";
$query2 = "SELECT p.surname, f.destination FROM PASSENGER p, FLIGHT_INFO f WHERE p.username = '$loggedinuser' AND p.flightNo = f.flightNo";
$result = mysql_query($query2);
while($row = mysql_fetch_array($result))
{
"<form>"
<input type="text" name="firstname" value="<?php echo {$row['surname']} ?>" disabled />
"</form>"
}
echo mysql_error();
?>
How can a new line be added between echo’s in the following code please?
echo ' Surname: <input type="text" name="surname" value="'.$row['surname']. "\" disabled /> ";
echo 'Forename: <input type="text" name="surname" value="'.$row['forename']. "\" disabled />";
echo 'Email Address: <input type="text" name="surname" value="'.$row['emailAddress']. "\" disabled />";
echo 'Preference ID: <input type="text" name="surname" value="'.$row['dob']. "\" disabled />";
echo 'Seat Number: <input type="text" name="surname" value="'.$row['seatNo']. "\" disabled />";
echo 'Group ID: <input type="text" name="surname" value="'.$row['groupID']. "\" disabled />";
1 Answer