Hi there,
I'd be ever so greatful if someone could help me please. I'm really trying to get my head around working with arrays and could really do with an example in a context i fully understand.
I have made a test page for this and made a query that will search for appropriate records in my database:
<?php $colname_Class = "3";
$colname_Ships = "-1";
if (isset($_SESSION['MM_Username'])) {
$colname_Ships = (get_magic_quotes_gpc()) ? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_swb, $swb);
$query_Ships = sprintf("SELECT * FROM ships WHERE PlayerName = %s AND Class=%s AND Template='1'", GetSQLValueString($colname_Ships, "text"),
GetSQLValueString($colname_Class, "int"));
$Ships = mysql_query($query_Ships, $swb) or die(mysql_error());
$row_Ships = mysql_fetch_assoc($Ships);
$totalRows_Ships = mysql_num_rows($Ships);
echo $row_Ships['ShipID']; echo ' ';
echo $row_Ships['ShipName']; echo ' ';
echo $row_Ships['Class']; echo ' ';
echo ' ';
echo $totalRows_Ships = mysql_num_rows($Ships); ?>
After i made the query i echo out the ShipID, ShipName and Class from the queey which displays:
5 New Ship 3 1
So you can see the ShipID = 5, the name of the Ship is New Ship, its Class is 3 and there is only 1 record found in the database that matches the search criteria.
Lets say there are 10 records in my database... What i really need to do is make an array of the outputted results, determine the number of records and then to randomly choose 1 of the results from the array.
Can you help me please?? If i can see an example in this context i feel i'd really learn something here.
If you can help, please do because im well stuck.
Thank you