PHP - Question About 'select * ___ Where
i have this code
SELECT COUNT(*) as num FROM videos where title=$title and if the title has punctuation marks for example "psssh's psh" it would interpret it like 'SELECT COUNT(*) as num FROM videos where title=psh's psh ' right? and then it shows this error 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 's psh ORDER by (eno+0) DESC' at line 2 i dont know what to do, i tried changing ' and "... and adding ' and " also... i also need something that with work with other symbols like & / * etc. Similar TutorialsI have a question concerning outputting information taken out of the database. Query is as follows: Code: [Select] $query = "SELECT * FROM users"; $results = $this->db->query($query); $result = $results->fetch_assoc(); return $result['username']; The value that returns is the first username in the database. But here I am selecting all the usernames, can I select others ones with the fetch_assoc? Hi. I have two select fields one called category and the other sub category. Both are in the format. <select name="category" value=" <?php $qGetCat = "SELECT * FROM club_category" ; $rGetCat = mysql_query($qGetCat); while ($Cat = mysql_fetch_assoc($rGetCat)) { ?>" /> <option value="<?php echo $Cat['categorys'];?>"><?php echo $Cat['categorys']; ?></option> <?php } ?> </select> <select name="sub_category" value=" <?php $qGetSubCat = "SELECT * FROM sub_categorys" ; $rGetSubCat = mysql_query($qGetSubCat); while ($SubCat = mysql_fetch_assoc($rGetSubCat)) { ?>" /> <option value="<?php echo $SubCat['sub_categorys'];?>"><?php echo $SubCat['sub_categorys']; ?></option> <?php } ?> </select> Now I want to make it so that when a particular category is chosen for example self defence. The sub category when clicked shows all the self defence stuff. If watersports was chosen sub category would show things like swimming. What do I need to look up to do this? At the minute there is no link the way I have coded these to fields. In the database its self there is a; category table with categoryID and category_name sub category table with sub_cat_name and categoryID I think this will work but I have never done this so its making my head hurt just thinking about it. Does anyone have any advice, tuts or scripts to do this? Thank you Hello, guys! Just a small first ever thread, where I ask a question where I hope anyone is able to help me out I am working on a project with a friend of mine for a company. I have a problem with the function on a form. I wonder; How do i change the option value of a form? Let's say if I choose a category like "Cake", I want the second drop down box to display different brands of cake. But if I choose bicycle for example, I want the option values to be different brands of bicycles. I hope you guys understand what I was trying to say here. Anyways, here is a sample image where I want this function to occur: Sample: Cheers and thanks in advance, Marius Can anybody clarify the usefulness of "AS" and elaborate on how it operates. If I select a 'bananas' AS 'yeelow fruit' will it change the TITLE in the table? Or the table that is being viewed? If I dump a list of 'FRUITS' into and HTML table, will using AS rename each column for me, or is that handled by MY coing of the HTML table? This is what i have Code: [Select] $traderss1=mysql_query("SELECT * FROM `poke_owned` WHERE `box`='1' AND `trainer`='" . $trading->username . "' ORDER BY `name` ASC"); How can i do this: Code: [Select] $traderss1=mysql_query("SELECT * FROM `poke_owned` WHERE `box`='1' AND `trainer`='" AND `traded`='0' . $trading->username . "' ORDER BY `name` ASC"); I know its not as simple as just adding AND `traded`='0' cause i tried that and i just got this Code: [Select] Parse error: syntax error, unexpected '=' in /home/tpkrpgn1/public_html/trade5.php on line 57 MySQL table (in case you need to know it?) Code: [Select] (`id`, `trainer`, `gender`, `name`, `party1`, `party2`, `party3`, `party4`, `party5`, `party6`, `level`, `exp`, `hp`, `totalhp`, `att`, `def`, `box`, `days`, `battle_wins`, `battle_losses`, `move1`, `move2`, `move3`, `move4`, `attbon`, `defbon`, `totalexp`, `sold`, `traded`, `item`, `soldtrainer`) This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=322629.0 I am working on a quiz app image 1 shows the index.php page image 2 shows the first question image 3 shows the second question image 4 shows the third question image 5 shows the result after completing the quiz image 6 shows the database 'quizzer' and its tables image 7 shows the 'questions' table image 8 shows the 'choices' table THIS LINK CONTAIN ALL THE CODE (and images) I HAVE DONE SO FAR https://www.mediafir...o7f5q0fe6y/quiz 1.Now my question is how to select the question RANDOMLY from 'questions' table along with 'choices' (by adding code to the existing file or create a new one). 2.If user refresh/reload the page before starting ('Start Quiz') or click 'Take Again' after finishing the quiz, the question should appear randomly. 3.Basically I want to change the order of question appearing in the browser each time I refresh. 4.My work so far is mentioned above.........Please help me with this "RANDOM" problem !! P.S - Will it be possible, by creating a random function in PHP which will check for repeat questions in a session and check for the 'id' of the question and if it is new display it on the page. If so what should I do and if no then how to do? hirealimo.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> when in a form, I wish to build a conditional that if the response to a radio button is a value of 2 (female), it will display an input requesting for users maiden name. If not 2 goes to the next input statement. Here is code I was experimenting with: <html> <body> <form action="" name="test" method='POST'> <input type="radio" id="sex" value=1 checked><label>Male</label> <input type="radio" id="sex" value=2><label>Femaleale</label> <?php $result = "value"; if ($result == 2) echo "<input type='int' id='gradYear' size='3' required>"; else echo "Not a female!" ?> <input type="submit" value="GO"> </form> </body> </html> The code passes debug, however, Not a Female is displayed. My question is - Can I do this and if so, what value do I test against id='sex' or value. I tried each one but gave the same results. I realize that $_POST[sex] would be used after the submit button is clicked. But this has me stumped. Thanks for the assis in advance. 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 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
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 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 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 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, 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. |