i need to search the db for all records but the results are currently only search and showing the results for the first col in the database, i have tried some tutorials and tried a few variation but it doesnt seem to be working as the tutorials are echoing out the information within the loop but i dont want it like that.
i tried this
[php]mysql_select_db($database_TickTo, $TickTo);
$query_rsVoucher = “SELECT * FROM TickTo_vouchercode”;
$rsVoucher = mysql_query($query_rsVoucher, $TickTo) or die(mysql_error());
$row_rsVoucher = mysql_fetch_assoc($rsVoucher) or die(mysql_error());
Well a while loop is the correct way to get all the rows from the db. What are you trying to achieve. You say you don’t want it echoed or you don’t want to use a while loop? Explain further please. If you’re wanting to put all the rows into a variable then this should do it.
[php]
mysql_select_db($database_TickTo, $TickTo);
$query_rsVoucher = “SELECT * FROM TickTo_vouchercode”;
$rsVoucher = mysql_query($query_rsVoucher, $TickTo) or die(mysql_error());
$row_rsVoucher = mysql_fetch_assoc($rsVoucher) or die(mysql_error());
i have a discount code(voucher) that when the user adds a code to a form field it checks the database to make sure that code is a real one then applys the discount
If you’re just trying to see if a specific value is in a database row then you would use a WHERE clause in the query to find that value.
[php]
$code = mysql_real_escape_string($_POST[‘vouchCode’]);
$query_rsVoucher = “SELECT * FROM TickTo_vouchercode WHERE VCode = {$code}”;
[/php]
Then just check if the query returned any rows. If it did then the code is valid, if no rows returned then it’s not valid.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘‘TickTo_vouchercode’ WHERE ‘VCode’ =’ at line 1
i did miss a part of the code out so though i would post it again…if thats ok (this is all the voucher code script)
[php]if ((isset($_POST[“MM_update”])) && ($_POST[“MM_update”] == “form2”)) {
$updateSQL = sprintf(“UPDATE TickTo_voucher SET vouchCode=%s WHERE vouchID=%s”,
GetSQLValueString($_POST[‘vouchCode’], “text”),
GetSQLValueString($_POST[‘vouchID’], “int”));
mysql_select_db($database_TickTo, $TickTo);
$Result1 = mysql_query($updateSQL, $TickTo) or die(mysql_error());
}[/php]
this is the modified version
of the next part
[php]$code = mysql_real_escape_string($_POST[‘vouchCode’]);
mysql_select_db($database_TickTo, $TickTo);
$query_rsVoucher = “SELECT * FROM ‘TickTo_vouchercode’ WHERE ‘VCode’ = {$code}”;
$rsVoucher = mysql_query($query_rsVoucher, $TickTo) or die(mysql_error());
$row_rsVoucher = mysql_fetch_assoc($rsVoucher) or die(mysql_error());
$totalRows_rsVoucher = mysql_num_rows($rsVoucher);[/php]