Validation for 3 instances [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm trying to put a validation for when you get the same date, with the same time and same venue, it will not insert in the database. It will only insert in the database if 1 instance will return false.
$res_date = $_POST['res_date'];
$res_venue = $_POST['res_venue'];
$res_dur = $_POST['res_duration'];
$qryjay = mysql_query("SELECT * FROM tbl_reservation WHERE res_date='$res_date' AND res_dur = '$res_dur' AND res_venue = '$res_venue'");
if ((mysql_num_rows($qryjay) == $res_date) && ($qryjay == $res_dur) && ($qryjay) == $res_venue){
echo "<script language=javascript>alert('".$res_venue." is not available on ".$res_dur." on ".$res_date."!')</script>";
}

Try to fix your code like this:
<?
$res_date = mysql_real_escape_string($_POST['res_date']);
$res_venue = mysql_real_escape_string$_POST['res_venue']);
$res_dur = mysql_real_escape_string$_POST['res_duration']);
$qryjay = mysql_query("SELECT count(*) as countNbr FROM tbl_reservation WHERE res_date='".$res_date."' AND res_dur = '".$res_dur."' AND res_venue = '".$res_venue."'");
$result = mysql_fetch_assoc($qryjay);
if ($result['countNbr'] > 0)){
echo "<script language=javascript>alert('".$res_venue." is not available on ".$res_dur." on ".$res_date."!')</script>";
}
?>

Related

Mysql search - in which don't have dots [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to search MySQL table and get in result in which don't have . (dot). example is below
example1.com
example2.com
example3
example4 com
So i want return, example 3 and 4. So basically i want row which don't have . (dot).
You can just use NOT LIKE:
SELECT column
FROM tablename
WHERE column NOT LIKE '%.%'
You can do that #fthiella suggested, or you can filter your search results in this was, using the stristr PHP function:
<?php
$searchQuery = 'example';
$sql = 'SELECT * FROM yourTable WHERE domain LIKE "%' . mysql_real_escape_string($searchQuery) . '%"';
$query = mysql_query($query);
$total = mysql_num_rows($query);
if($total) {
$data = array();
while($row = mysql_fetch_array($query)) {
if(stristr($row['domain'], '.') !== false) {
$data[] = $row['domain'];
}
}
die('<pre>' . print_r($data, true) . '</pre>');
} else {
die('Nothing was found.');
}
Note that I don't know your database table structure, so this is a psuedo-example.

exploded string manipulation [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have already seen examples for string manipulation using "explode" but none of them does my job..
I have an array of exploded strings:
$grand_result = 12,5,7,3,2,1 ;
$grandparent_id = explode(",",$grand_result);
i want to insert some values in db having id = $grand_result except first value returned (12) in this case
$grand_result can have many values i want to fetch only first 7 values..
how can i do that ...thanks in advance
you can use array_slice
$output = array_slice($grandparent_id, 0, 7);
$grand_result = "12,5,7,3,2,1" ;
$grandparent_id = explode(",",$grand_result);
first update
$avoid = grandparent_id[0];
foreach ($grandparent_id as $id) {
if ($avoid != $id) {
//run your update query
}
}
second fetch
$query = "select * from `table_name` where id in (".$grand_result.") limit 7";
Set Limit of explode
$grand_result = 12,5,7,3,2,1 ;
$grandparent_id = explode(",",$grand_result,8);
unset($grandparent_id[7]); or $grandparent_id = array_slice($grandparent_id, 0, 7);

Getting the player with the most kills with a specific weapon [mysql] [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Im trying to find the best killer (most kills) out of a kills database.
Put the killerId of $important into an array, and compare it with the rest of the killers. Find the best killer with the weapon $important.
How do I do that?
$array = array();
$index = 0;
while($mData = $q->fetch_assoc())
{
$index++;
$arr = explode('with ', $mData['killText']);
$unimportant = array(" (in paintball)", " (in event)");
$important = str_replace($unimportant, "", $arr[1]);
if(empty($important)) { $important = "Suicide"; }
$array[$important]['Kills']++;
$array[$important]['Gun'] = $important;
$query2 = $mysql->query("SELECT * FROM `kills` WHERE `killText` LIKE '%$important%' AND `killerID` = '". $mData['killerID'] ."'") or die($mysql->error);
while($kData = $query2->fetch_assoc())
{
// put the killerId of $important into an array, and compare it with the rest of the killers. Find the best killer with the weapon $important
}
}
A GROUP BY will do the trick:
"SELECT killerID, COUNT(*) FROM kills WHERE killText LIKE '%$important%' GROUP BY killerID;"
You ca just fetch "killerID" and got the killer with most kills of weapon $important:
$kData = $query2->fetch_assoc();
$kData['killerID'];

mysql php if else inside while loop [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
$sql = mysql_query("SELECT DISTINCT business_region FROM business WHERE business_category='occupation'");
// count the output amount
$businessCount = mysql_num_rows($sql);
if ($businessCount > 0) {
while ($row = mysql_fetch_array($sql)) {
$business_region = $row["business_region"];
$Region_view .= "display value";
}
}
This gives a following result:
Michigan Toronto Ohio Manchester London Sydney Paris
I want to select only Ohio and London
as a variable value as:
$Region_view .
Perhaps I can use if else structure, but I could not get it to work.
i.e. I need to select only Ohio, London
I can do it using joint MySQL statement but it is too slow so I need and ask for a different way.
$sql = mysql_query("SELECT DISTINCT business_region FROM business WHERE business_category ='occupation'");
// count the output amount
$businessCount = mysql_num_rows($sql);
if ($businessCount > 0) {
while($row = mysql_fetch_array($sql)){
$business_region = $row["business_region"];
if ($business_region == 'Ohio' || $business_region == 'London') // added
$Region_view .= $business_region;//changed
}
}

why auto dupplicate value in my array [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I tried to create a shopping basket in my project, but some problem to handle this.
My project basket must allow duplicate value, but my code auto duplicate last insert to array. Why does this happen, and how to solve this auto duplicate?
<?php
if(isset($_SESSION['basket'])){
$point = count($_SESSION['basket']);
echo " point = ".$point;
$value = end((array_keys($_SESSION['basket'])));
$value++;
}else{
$value = 0;
echo " point = 0";
}
if(isset($_GET['id'] , $_GET['meter'] , $_GET['color'])){
$id = $_GET['id'];
$color = $_GET['color'];
$meter = $_GET['meter'];
$selected_product = array($id , $color , $meter);
list($_SESSION['basket'][$value][0],$_SESSION['basket'][$value][1] , $_SESSION['basket'][$value][2]) = $selected_product;
echo "<pre>";
var_dump($_SESSION['basket']);
echo "</pre>";
}
?>
Though its not exactly clear from your question. To remove duplication in array use array_unique()
You also had a typo at
array($_SESSION['basket'][$value][0],$_SESSION['basket'][$value][1] , $_SESSION['basket'][$value][2]) = $selected_product;

Categories