PHP - Select
Hi everyone!
I need to know how to write two $what_services variables in so it looks for both "R" AND "B".. R and B are values within my db table, here's the code: Code: [Select] <?php $what_services = "R"; $query = "SELECT * FROM companies WHERE what_services = '$what_services' ORDER BY approved DESC, company_name ASC"; $result = mysql_query($query); ?> iv'e tried the following but have gotten undesired results: two what services like so; $what_services = "R"; $what_services = "B"; separating with comma's; $what_services = "R, B"; Using AND; $what_services = "R AND B"; None of which works, what is the correct way to write this? Thanks Similar Tutorialshirealimo.com.au/code1.php this works as i want it: Quote SELECT * FROM price INNER JOIN vehicle USING (vehicleID) WHERE vehicle.passengers >= 1 AND price.townID = 1 AND price.eventID = 1 but apparelty selecting * is not a good thing???? but if I do this: Quote SELECT priceID, price FROM price INNER JOIN vehicle....etc it works but i lose the info from the vehicle table. but how do i make this work: Quote SELECT priceID, price, type, description, passengers FROM price INNER JOIN vehicle....etc so that i am specifiying which colums from which tables to query?? thanks I have 2 queries that I want to join together to make one row
Dear All, I wish to have 2 drop down boxes, Country Select Box and Locality Select Box. The locality select box will be affected by the value chosen in the country select box. All is working fine except that the locality select box is not being populated. I know that the problem is in the sql statement WHERE country_id='$co' because i am having an error that $co is an undefined variable. All the rest works fine because i have replaced the $co variable directly with a number (say 98) for a particular country id and it worked fine. In what way can i define this variable $co so that it is accepted by my sql statement? Thank you for your help in advance. MySQL Tables indicated below: CREATE TABLE countries( country_id INT(3) UNSIGNED NOT NULL AUTO_INCREMENT, country_name VARCHAR(30) NOT NULL, PRIMARY KEY(country_id), UNIQUE KEY(country_name), INDEX(country_id), INDEX(country_name)) ENGINE=MyISAM; CREATE TABLE localities( locality_id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, country_id INT(3) UNSIGNED NOT NULL, locality_name VARCHAR(50), PRIMARY KEY (locality_id), INDEX (country_id), INDEX (locality_name)) ENGINE=MyISAM; Extract PHP script included below: // connect to database require_once(MYSQL); if(isset($_POST['submitted'])) { // trim the incoming data /* this line runs every element in $_POST through the trim() function, and assigns the returned result to the new $trimmed array */ $trimmed=array_map('trim',$_POST); // clean the data $co=mysqli_real_escape_string($dbc,$trimmed['country']); $lc=mysqli_real_escape_string($dbc,$trimmed['locality']); } ?> <form action="form.php" method="post"> <p>Country <select name="country"> <option>Select Country</option> <?php $q="SELECT country_id, country_name FROM countries"; $r=mysqli_query($dbc,$q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); while($row=mysqli_fetch_array($r)) { $country_id=$row[0]; $country_name=$row[1]; echo '<option value="' . $country_id . '"'; if(isset($trimmed['country']) && ($trimmed['country']==$country_id)) echo 'selected="selected"'; echo '>' . $country_name . '</option>\n'; } ?> </select> </p> <p>Locality <select name="locality"> <option>Select Locality</option> <?php $ql="SELECT locality_id, country_id, locality_name FROM localities WHERE country_id='$co' ORDER BY locality_name"; $rl=mysqli_query($dbc,$ql) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); while($row=mysqli_fetch_array($rl)) { $locality_id=$row[0]; $country_id=$row[1]; $locality_name=$row[2]; echo '<option value="' . $locality_id . '"'; if(isset($trimmed['locality']) && ($trimmed['locality']==$locality_id)) echo 'selected="selected"'; echo '>' . $locality_name . '</option>\n'; } // close database connection mysqli_close($dbc); ?> </select> </p> <p><input type="submit" name="submit" value="Submit" /></p> <input type="hidden" name="submitted" value="TRUE" /> </form> Hi, what I want to figure out is for instance a person has registered with their country e.g. England. Now if I echo the country in a select box giving the person an option to change their country and Showing the person which currently they have selected already. The select box shows two England`s to select from. Could some one tell me how can I have one of each country and echo their already selected country from the database. I don't know how to explain any better what I am after but just basically there are two Englands showing one which is already selected (echoing from the mysql database) and one is already in the select box. Any help is much appreciated thank you. Hi all, Im trying to get the requested genre and compare it with the <SELECT> list to add the word SELECTED on the option. So if the requested genre is the same as the option name them make that the SELECTED option. Cheers. Here's a bit of code I made that does not work Code: [Select] <? function selected(){ if ($_REQUEST['genre'] = $name){ echo"SELECTED"; }} ?> Gen <SELECT class="sort" align="right" onChange="window.location.href=this.options[this.selectedIndex].value;"> <option value="<?=$_SERVER['PHP_SELF'];?>" <?$name = ''; selected(); ?>>Any</option> <option value="<?=$_SERVER['PHP_SELF'];?>?genre=Action" <?$name = 'Action'; selected(); ?>>Action</option> <option value="<?=$_SERVER['PHP_SELF'];?>?genre=Adventure" <?$name = 'Adventure'; selected(); ?>>Adventure</option> <option value="<?=$_SERVER['PHP_SELF'];?>?genre=Animation" <?$name = 'Animation'; selected(); ?>>Animation</option> </SELECT> ok here's my problem $Sql1 returns two values: 8 and 10 and these numbers get put into a <select>. So far so good. I assign a onchange to it. When i select 8 it makes the changes but when I select 10 nothing happends. I preciate some help. Code: [Select] <?php require("status.php"); require("id.php"); $Link = mysql_connect($Host, $User, $Password); mysql_select_db('sportsportal', $Link); $Sql1 = "select distinct week, (select max(week) from coupons where user='$User') max from coupons where user='$User'"; $Result1 = mysql_query($Sql1, $Link); print "<tr>"; print "<td align=left valign=top> </td>"; print "<td align=left valign=top>"; print "<select name=current_week onchange=window.location='coupon.php?curwk='+this.value>"; while($Row1 = mysql_fetch_array($Result1)){ //if($Row1[week] == $Row1[max]){ //print "<option value='$Row1[week]' selected>Vecka $Row1[week]</option>"; //} else { //print "<option value='$Row1[week]'>Vecka $Row1[week]</option>"; //} print "<option value='$Row1[week]'>Vecka $Row1[week]</option>"; } print "</select>"; print "<p></td>"; print "</tr>"; if(isset($_REQUEST['curwk'])){ $Curwk = $_REQUEST['curwk']; } else { $Curwk = 0; } $Sql = "select home, away, home_score, away_score, winner from coupons where user='$User' and week='$Curwk'"; $Result = mysql_query($Sql, $Link) or die(mysql_error()); while($Row = mysql_fetch_array($Result)){ if(@$Row[home] == @$Row[winner]){ print "<tr>"; print "<td align=left valign=top> </td>"; print "<td align=left valign=top><b>$Row[home]</b> - $Row[away] $Row[home_score]-$Row[away_score]</td>"; print "</tr>"; } else { print "<tr>"; print "<td align=left valign=top> </td>"; print "<td align=left valign=top>$Row[home] - <b>$Row[away]</b> $Row[home_score]-$Row[away_score]</td>"; print "</tr>"; } } mysql_close($Link); ?> I'm trying to run a readout of a db which runs fine as an individual script. When I embed it in PHP inside an html div container, it bails when it encounters the first ">" and simply outputs the PHP characters from there through the "?>". The rest of the html runs fine before and after. For example, this line echo "<select>"; would output "; and any other php script up to the ?> end, after which it renders html fine. If I run the script as a separate php file, it runs as expected. Any help would be appreciated. Thanks. Hi, I'm trying to make a 3 page registration form. On the 3rd page I want it to echo back all the options they have selected. I can get the input type to work but having problems with the selects. First Page Code: [Select] <form action="choose.password.php" method="post"> eMail: <input type="text" name="eMail" /><br /> Forename: <input type="text" name="fname" /><br /> Surname: <input type="text" name="lname" /><br /> Date of Birth: <input type="text" name="dob" /><br /> Gender: <select name="gender"> <option value="male">Male</option> <option value="female">Female</option> </select> <br /> I am not a lawyer: <input type="checkbox" name="lawyer" value="lawyer"> <br /> <br /> <input type="submit" value="Next" /> </form> Second Page Code: [Select] <form action="confirm.details.php" method="post"> <p>email address: <?php echo $_POST["eMail"]; ?></p> <p>password: <input type="password" name="eMail" /></p> <p>Confirm Password: <input type="password" name="eMail" /></p> <p>Hint: <input type="text" name="hint" /></p> <p>My email is correct, I am happy to be sent occassional emails, and i am not a family lawyer. <input type="checkbox" name="lawyer" value="lawyer"></p> <input type="hidden" name="fname" value="<?php echo ($_POST["fname"]); ?>" /> <input type="hidden" name="eMail" value="<?php echo ($_POST["eMail"]); ?>" /> <input type="hidden" name="lname" value="<?php echo ($_POST["lname"]); ?>" /> <input type="hidden" name="dob" value="<?php echo ($_POST["dob"]); ?>" /> <select style="display:none;" name="gender" <?php echo ($_POST["gender"]); ?> /> <p><input type="submit" value="Next" /></p> Third page Code: [Select] <p>Please confirm your details are correct to register.</p> <p>Email Address: <?php echo $_POST["eMail"]; ?> <p>Forename: <?php echo $_POST["fname"]; ?></p> <p>Surname: <?php echo $_POST["lname"]; ?></p> <p>Date of Birth: <?php echo $_POST["dob"]; ?></p> <p>Gender: <?php echo $_POST["gender"]; ?></p> How can I make the select work and echo it back on the third page? Thanks I'm using a PHP helpdesk script, but when a customer submits a ticket, they are able to assign a category. I want to be able to have the category function so I can move tickets around, but only allow customers to assign to one. (Basically I want to hide the Select Box on the new ticket page) This is the code which displays the select box: Quote <td style="text-align:right" width="150"><?php echo $hesklang['category']; ?>: <font class="important">*</font></td> <td width="80%"><select name="category"> Can you tell me what I can do to "hide" the category select box without getting rid of it? (The page requires a variable for category) Thanks Code: [Select] id player_id nat nt_caps 13740 28664 97 24 13741 28664 68 0 13742 28664 79 0 16252 42904 15 40 16253 42904 68 0 16254 42904 241 0 That's how my table looks. I want to select the player_id's that have either nt_caps = "0" for every nat OR player_id's that have nt_caps != "0" only for nat = "68". The SQL query I try to use is: SELECT player_id FROM x WHERE nat = '68' AND (nat != '68' AND nt_caps = '0') But then I get player_id '42904' and '28664' because they both have 1 entry that matches the query but I don't want them because they have nt_caps for another nat than nat "68". I hope you understand what I try to achieve. Code: [Select] $query ="SELECT id,today,uuendus,username FROM u_data WHERE today < '$datex' AND uuendus='YES' ORDER BY id ASC";i want select older then $datex all other code is correct i just want to know is Code: [Select] WHERE today < '$datex' correct to use? hi. just started a website talkietaco.com and at the momment my code selects the first row and displays it. this is all well and good but when i add a new row to the table it gos to the bottom. I want to be able to select the last row and echo it out. Any ideas? would i need to add an id row or something? Heres the code and thank you in advance for any help people can offer. Code: [Select] <?php $con = mysql_connect("localhost","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mainbase", $con); $result = mysql_query("SELECT * FROM matteroffact"); echo "<table border='0'> <tr> <th></th> </tr>"; $row = mysql_fetch_array($result) or die(mysql_error()); echo "<tr>"; echo "<td><strong>" . $row['question']. "</strong> ". $row['answer']; "</td>"; echo "<tr>"; echo "</table>"; ?> Hi Guys
I have a table which in it's shortened form has the following columns:
id | postID | title | content | version
The column for postID has a number that can be shared by multiple rows - differentiated by version number.
I want to run a query to select all records that are like a given keyword (i.e. %LIKE%) but where results share the same postID I only want to return the highest version number for that record.
The difficulty is some records may have multiple version numbers that match the like statement and some may have only one. So this variance with the LIKE search is causing me some confusion.
I've tried this in a few ways using a sub-query but for the life of me I cannot work out how to do it.
Any help would be appreciated,
Drongo
hi guys ive just finished this task after hours of head scratching since svg is only really supported good in firefox and opera ive chosen firefox as my browser to view this url www.deansignori.com/phpsvgpie/index.php i do need more help with this task but a different problem (creating select box to call different stylesheet and to change from 2d - 3d i have the code set out so that i can explode any segment or change size of slices or change from 2d-3d but i have to do this manually in the code to render different piecharts im wanting to use 1 but change it using a select box and echo my variable into it basically im unsure of the syntax for this problem psuedo code for style maybe something like if select box value isset onchange stylecolour echo stylecolour if select box value isset onchange stylegrey echo stylegrey and for 3d-2d if select box value isset onchnage format3 echo format3 if select box value isset onchange format2 echo format2 this would be on my index page can anyone advise me please regards Dean Hi I have some website code that has worked fine up to now. I enter a day / month and / year. I tried to change the txt box for the day into a drop down list. and the submission $_POST fails. This works <input style="text-align:right;" type="text" size="1" maxlength="2" name="DD_Balance" value="<?=$_SESSION["DD_Balance"]?>"> /
This doesn't
<select name="DD_Balance" style="width:40px">
Confused as the names of the objects are the same. Also view text is all screwed up on several lines not underneath each other. Hello dear friends, If i've database table has named as info (id, name, number) and i wanna say select from info where name must has value not empty Code: [Select] select * from info where name='xxxxwhatxxx' i've tired $name and $1 and 1 but all not working how to say where name must has value and not empty example if i've Code: [Select] (id, name, number) values (1, 'manal', '4') (id, name, number) values (2, 'shimaa', '7') (id, name, number) values (3, '', '3') and i wanna say sellect from info where name has value so it shows me only data of id "1" and "2" only thank you so much it would helps me alot to improve myself Hello,
i am starting to freak out ... i am trying to make a select but it dont want to work.
So what do i have:
i have 2 Tables
table 1: customer (contains the name) (fieldname: name)
table 2: bookings (contains the name from customer) (fieldname: belegung)
in table 2 there are multiple lines with lets say 10 customer xyz and 3 customer xxx
in table 1 every customer is only once and it includes 5 customer
my output i want to have now is a group by where i have the customer in column 1 and the count(*) in column 2
so in my case
customer xyz - 10
customer xxx - 3
customer 3 - 0
customer 4 - 0
customer 5 - 0
i only manage to group them, so i can see it like
customer xyz - 10
customer xxx - 3
customer 3 - 1
customer 4 - 1
customer 5 - 1
as it goes on the count(*) from table 1
please if someone could help me i would be pleased
I am trying to get an id from a table where clientid is equal to a session var. I know the session is set because if I echo it, it shows up, and I know there is a row in the db that matches because I am looking at it right now. The problem is, the query is not selecting any data. I need to select the clientid from the table so I can set another session var. Please please help my brain is not coping! Thank you! <? session_start(); $uid = $_SESSION['logid']; include('../connectdb.php'); mysql_select_db("maindb", $con); $result = mysql_query("SELECT * FROM projects WHERE clientid = $uid"); while($row = mysql_fetch_array($result)) { echo $row['id']; } ?> I'm down to just echoing the row to problem solve but nothing comes up. Hi guys, I'm having a issue with a little bit of coding involving SELECT the problem is I want it to select from the database and say limit it to 5 so basicly it prints 5 results from the database but its only printing 1 result Here is the code i'm using Code: [Select] $q=mysql_query("SELECT * FROM papercontent LIMIT 5",$c); $content=mysql_result($q,0,0); print " <center><table width = '40%' border = '1'><tr><th> <center><u>Latest Announcements</u></center> $content </tr></td></table> "; Thanks I'm trying to write a select to match a few certain words... $sql = "SELECT * FROM podcasts WHERE `type` = 'podcast' AND recap LIKE 'Men%' AND recap LIKE '%Hockey%' ORDER BY date DESC"; That's what I have so far...which isn't working... I need to match the string "Mens" OR "Men's" with the word "Hockey" BUT...I can't match "Women's" or "Womens" Any idea what I'm doing wrong? The above code only returns 6 results...when it should return nearly 100. Thanks! |