Switch Statement + Reading From MySQL DB
I have created a templated site, with the use of switch statements [shown below] Anyway, this works fine, accept the person I am doing this for knows little html so what I want to do is be able for him to add new sections easily without doing any HTML, thus the MySQL DB.
But I am stumped what is the best way to do this?? I would be very grateful if someone can help.. PHP Code:
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Switch Statement
<?php switch ($var) { case ("02100" || "02700" || "02500"): /* rest of code...... */ break; } ?> Does this work? (i mean the || statement(s) in combination with a switch statement?
SQL With A Switch Statement ?
can you use a switch statement with mysql and how would i do it with the following ? require ('db_connect.inc'); $query ="SELECT abs_value, SUM(abs_value) FROM absence_mgt WHERE ID='$vtc_login' GROUP BY abs_value "; while ($row = mysql_fetch_array($run)) { if ($row['abs_value'] == 1) { $late_num = $row; }elseif ($row['abs_value'] == 2) { $sick_num = $row; }elseif ($row['abs_value'] == 3) { $sickhf_num =$row; }elseif ($row['abs_value'] == 4) { $awol_num =$row; }}
'switch' Statement
I'm delving into 'switch' statements instead of if/else to test the waters. I'm confused on a couple of things. First, i've created a simple form assuming I can populate the $var with a post from a form field then have it check through the 'switch' statement, find the right case and display the appropriate code. Simple! Code:
Switch Statement
I have an html page that lets the user select the type of item they wish to add to the library, a book, dvd, or cd. That page has a form which connects to this page, where the information should be entered, and I hope to have this page connect to another page where the items will actually be entered into the database. Code:
Looping In A Switch Statement
Does anyone know if this is possible, I am trying to iterate sections out of a mysql DB, I am getting a parse error..not sure if this CAN be done.
Two-dimensional Switch Statement?
I have a bunch of conditions in which to determine different types of questions to ask in a survey I am constructing. Just was wondering if anybody has used a two-dimensional switch statement. If this works, is this an efficient coding method or would anybody else have another way around this? $type = enters _POST as (employee, client, or peer) $visit = enters _POST as ( 0 or 1 ) $userage = enters _POST as ( 1, 2, 3, or 4) $ip is the IP address of the user function determineUser($type, $userage, $ip, $visit) { switch ($type){ case 'employee': switch ($userage){ case Ƈ': case ƈ': if($visit){$surveyType=1;}else{$surveyType=2;} break; case Ɖ': case Ɗ': $surveyType=3; break; case 'client': if($visit){$surveyType=4;}else{$surveyType=5;} break; case 'peer': if($visit){$surveyType=6;}else{$surveyType=7;} break; } $query = "INSERT INTO user(userip, userage, idsurvey) VALUES('$ip','$userage','$surveyType')"; mysql_query($query); return (getUserId($ip)); }
Problem With A Switch Statement
I have the following problem: When i use "scooters" in the value of the radio as well as in the switch statement, the code doesn't get executed, but if i use "scooter" it does. Is there something wrong with my code? -------------------------- Code is as follows: <?php fuction vehicles($selection) { .... .... echo $selection; } ?> .... .... <form method="get" action="select.php"> <table align="center" width="70%" border="1" cellspacing="2" cellpadding="2"> <tbody> <tr> <td width="100%" colspan="3" align="center">Select a Vehicle </td> </tr> <tr> <td width="25%"><br><input type="radio" name="vehicle" value="scooters">Motos / Scooters </td> <td width="25%"><br><input type="radio" name="vehicle" value="cars">Autos / Cars </td> <td width="25%"><br><input type="submit" value="Seleccionar"> </td> </tr> <?php $selection = clean($_GET["vehicle"], 7); if (!empty($selection)) { switch ($selection) { case "scooters": echo "<tr><td>"; vehicles($selection); $selected_type = $selection; echo "</td><td></td><td>" . $selected_type . "</td></tr></tbody></table>"; break; case "cars": echo "<tr><td></td><td>"; vehicles($selection); $selected_type = $selection; echo "</td><td>" . $selected_type . "</td></tr></tbody></table>"; break; } //End switch /* Set $selection to empty for the case the user made a mistake ** and wnts to select other type of vehicle */ $selection =""; } // End if ?> </tbody> </table> </form>
Switch Statement With Varchar?
I have a database for a member listing. I have 1 table organized as follows: id name sex The "sex" field can either be Male or Female. In the table, it is defined as 'sex varchar(20)'. I want to calculate the total number of males, and the total number of females, but I ran into problems trying to compare strings. Does PHP even support the comparison of strings? Code:
Switch Statement Not Functioning In URL
I was trying to run a switch statement with open url and its not working. the statement runs correctly when the variable is embedded in the script. i'm running this from a home computer with XAMPP (comes with Apache 2.2 and PHP 5.2.3 among other things). Whats the problem here?
Switch Statement With Extended Testing
Is there a way of building a 'switch' control structure, which tests for something OTHER THAN equivalence in each case? switch($val){ case ($val>=3 && $val<=6): do this; break; case ($val>3 && anothertest): do that; break; case ($val>6 && anotherone): do theother; break; default: $ermsg.="test on val failed"; } I guess it's purely academic - a series of if's would do the job, but in my case I am clamping 'vals' and testing against dozens of numerical ranges. A 'switch' could pass at the first test and be getting on with the next bit, leaving the 'ifs' standing!
Header() Ignored In Switch/case Statement
Can anyone tell me why in the 'unreg' part of this switch/case statement, the header() is being completely ignored? I am including the code for for the switch/case, plus the code on the page referenced in the header() redirect. PHP Code:
Multiple Forms Within A Switch Statement
I have to make this administation area where I have multiple Contents to add edit delete publish . The problem is that I don't know what is the best way of making the forms. At the moment I create a new PHP file for add_page.php, add_student.php, add_news.php, edit_page.php list_page.php and so on. This way doesn't seem very good to me and I am wondering if I want to put them in one file or in some more generic files, how am I going to do that. For start created the content.php and did a switch $_GET['category'] and a nested $_GET['action'] but I don't know what each case: should contain. I don't want to put the whole html code for the forms in each case.... I have tried puting each form in a function but I had some stupid errors and that also doesn't sound to me a good solution. So if someone has previous experience pls Suggest me something...
Checkboxes, $_POST Array, And Switch Statement
I'm having problems with a switch statement that is wrapped in a foreach statement so that each index in an array is evaluated against the switch statement. The switch/case will then return some output for display. I have a long list of classes for the upcoming semester. Each one has a checkbox to the right that has the following code. <input type="checkbox" name="course[]" value="i"> where i increases linearly with each class, i.e. first class value="1" second value="2". There are 41 classes for the semester. Upon submission of the form (Yes, I have a <form> tag with all the necessary parameters.), display.php (the action of the form) should loop through each key in the course array and evaluate the value against a switch statement. Here is what my PHP code looks like so far: if(isset($_POST['course']) { foreach ($_POST['course'] as $key => $value) { switch($value) case 1: echo 'foo' break; case 2: echo 'bar' break; default: echo 'Please select a course' break ............. I tried putting the case numbers in quotes like case "1": but that didn't make any different. What this will eventually do is pull book information for each class that is selected from Amazon and enable the user to quickly add the books to a shopping cart and check out. I shortened the code (leaving out the other 39 cases!) and I omitted the html that the PHP page contains. Can anyone explain what I am doing wrong with my switch statement and/or array?
Avoid A Long Array Switch Statement (for Pagination)
I am making a pagination system for a CMS. The CMS uses the smarty template engine so I am taking advantage of that. For those who don't know about smarty, anywhere in a code, you can place {tagname} and it will automatically call on the contents of tagname. There is also a little javascript in there aswell (including an include which gets a .js file), but that is irrelevant. Code:
PHP -> MySQL Insert Statement
heres what i am using : Code: if (($p1 == $p2) && ($p1 != " ")) {print "accepted"; print "<br>entering you into the database...."; $enter = 'INSERT INTO member(name, psw) VALUES("$name", "$p1")' $goenter = mysql_query($enter) or die("Entery Failed due to " . mysql_error());} else {print "<br><font size=+1>Password did not match, try again!</font>";}} ?> now heres the problem : when it writes to the table (all the db selection etc is fine) all that gets written is : "$name" and "$p1" literally $name and $p1 *** not their values. I have tried combinations of quotes ( as " " will interpolate but ' ' will not) but still no dice. and w/o the quotes around the values ("$name" , "p1") --- it will return an error stating the colum ($name value) does not exsist.
MySQL Conditional Statement
What I am trying to do is kind of like an advanced search. Basically, I have three dropdowns, for this I am going to use the example books: Three dropdowns, which are 1) Author 2) Language 3) Type (Hardback or Paperback) Typical search: I want to get a list of all books written by STEPHEN KING, that are written in ENGLISH and that are HARDBACK ok fine, but what if I just want to search for ALL books by STEPHEN KING regardless of the language or the type of book?? Heres the SQL i would use for all 3 "search parameters": PHP Code:
Mysql Query Statement
What I'm trying to do is search a field in mysql, and if it has an _ in the file name, change it to a - instead. And alos change any capital letters to lower case. From: This_is_my_example To : this-is-my-example I figure it would be something like: UPDATE 'file' SET '-' WHERE `filename` LIKE '_' I"m not really sure how to put a regular expression in there to only replace the underscore put leave the data.
Reading An MYSQL Row
I have a small problem. I want to read 3 colums that have information in MySQL. Here is an example: I have one column for users (userid), passwords (passid), for e-mail (emailid), and url(siteid). How can I read passid, emailid, and siteid and put them into a text box for a form. like: <!-- beginning --> $connect = @MYSQL_PCONNECT($host,$user,$pass); $query = MYSQL_DB_QUERY($db,"SELECT userid,passid,emailid,siteid FROM users WHERE userid = $user_logged") <!-- end --> what do i do to enter passid, emailid, and siteid that belong to $user_logged into their own text box , like in a form?
Quote Escaping For MySQL Statement
I'm doing a data migration and used gnumeric to change some big spreadsheets into .csv files for upload into a MySQL database through php. It seems to have done fine on my local machine, but it is dying on the production dB when it encounters a single quote, e.g. "The Manufacturer's specification ..." Right there------------------^ magicquotes is On Is there a handy extra function that can improves a string's chances of getting into MySQL cleanly? The setting for the csv export was "Always" (escape-quote everything)
MySQL - Using Expressions In ORDER BY Statement
I am currently teaching myself PHP/MySQL to add functionality to a website showing event listings for an entertainment venue. The events in any day can run from 11am until 3am. I have a search script that will return all events by title, time, date and other criteria and users can click on any column heading in the results to sort by that column. My problem is the event start time column. Sorting the data using "ORDER BY time" puts the post-midnight shows at the beginning of the list not the end. Does anyone have any ideas as to how I could adapt the ORDER BY part of the SELECT statement to return the post-midnight shows at the end of the list. I could presumably sort after deducting 4 hours off every time. Would something like ORDER BY (time-4) work (using simplistic shorthand for the "time-4")? I assume I would have to use the DATE_SUB() command but I am not sure about the format. The time is currently recorded simply as hh:mm:ss in the MySQL database.
PHP, MySQL, $_GET And If Statement Problem
I am having a issue that I have been working on for the last few days. I am using PHP 5, MySQL 4.1 and PEAR. The following code works by itself between <?php and ?tags: $isbn = $_GET['isbn']; $sql = "DELETE FROM lounge WHERE isbn = $isbn"; $db->query($sql); print $sql; Now, if I put it inside of an If statement, it does not work and I get a "DB Error: syntax error": if ($_POST['yes_no'] == 'yes') { $isbn = $_GET['isbn']; $sql = "DELETE FROM lounge WHERE isbn = $isbn"; $db->query($sql); print $sql; } else { print "Unable to delete record"; } This isbn is stored as an INT in MySQL. Does anyone have any ideas?
PEAR DB/MySQL Prepared Statement With LIKE
how to create a select statement using PEAR DB or MySQL with the LIKE function. That is I am looking of how I can get statement like this work. SELECT * FROM customer WHERE name LIKE '%?'
Question Regarding A MySQL SELECT Statement
I tried hunting for a MySQL specific NG and didn't find one but I did see that MySQL questions get asked here. If this isn't appropriate and you know of an appropriate NG then that would be great. In one table I have inventory... table name is "inventory" columns are.. ----------------------------- item_number item_name ----------------------------- 1 radishes 2 carrots 3 potatoes 4 oranges etc..etc Table two is "sold" ------------------------------ date item_number 13Mar 1 14Mar 4 15Mar 2 16Mar 1 What I am querying is the table "sold" for the Unique items (1,4,2) and then retrieving their names from table 1. My query below isn't working.. SELECT item_name FROM inventory WHERE inventory.item_number = sold.item_number; I am just now starting to get into complicated MySQL queries and actually the more I learn about it the more I love it.
Trouble MySQL AES_ENCRYPT() Using PHP For SQL Statement
I want to add a binary element (AES_ENCRYPT()) to a $_POST array. I need to make it binary because it is going into a BLOB field. $results = $dbr->Execute('select * from table1 where id='.$_GET['id']); .... // validation take place and now is processed $_POST["field1"] = $dbr->GetOne('select AES_ENCRYPT('.trim($_POST['field1']).', 'salt*&)#')'); // there are other $_POST fields that are in cluded in the next line // GetInsertSQL is a function that eventually calls $dbr->Execute() $dbr ->GetInsertSQL($results, $_POST, true); It decrypts most records (field1) but not all. After researching it, I think the problem lies in how I am adding the encrypted field. I think I need to make the $_POST["field1"] binary, somehow. If so, how do I do that?
Using Several Variables In A Mysql Statement In A Php Script
1. asking the user to select a teacher and adding to the hyperlink a variable ($id) to be used in the next page 2. showing a list of classes that teacher gave and ordering them by date or title. problems: 1. when i try and use variables for the "order by" function (one for $orderby and another for $direction), from some reason the query fails. I think that problem is about the other variable ($id) which is used in the same statement.... when i take that variable off and just enter a static number there is no problem. However trying to use these two or even three variables in the same mysql statement fails. any ideas? Code:
Help Req. Reading Data From MySQL Db With PHP
I have PHP code (below) which reads data from a MySQL format database. The problem I am having is trying to find out when the last ID entry was made. When the script is executed, the $gbID is supposed to be read and display the last entered ID number ($How_many_entries) - the ID number is entered / updated automatically in another PHP script which deals with data entry to the database. But instead of displaying the result of the query, it displays the ID number ($How_many_entries) as "Resource id #4", and looking around the search engines, no page makes particular sense as to what I've done wrong. Does anyone know how to get the $gbID number from the database and into $How_many_entries so I can perform some math work on it? <? $DatabaseName = "Guestbook"; $table_to_look_for = "entries"; $connection = @mysql_connect("localhost") or die("<B>Could not connect to MySQL: </B>".mysql_error()); mysql_select_db($DatabaseName); // get all tables in the database $result = @mysql_list_tables ("DatabaseName"); // Display database entries in reverse order (remove 'DESC' to have forward display of results) $sql = "SELECT gbID, gbDate, gbIP, gbURL, gbName, gbComment FROM $table_to_look_for ORDER BY gbid DESC"; $result = @mysql_query($sql, $connection) or die("<B>Problem reading from database: </B>".mysql_error()); while ($row = mysql_fetch_array($result)) { $gbID = $row['gbID']; $gbDate = gmstrftime('%A %d %B %Y at $T',strtotime($row['gbDate'])); $gbURL = $row['gbURL']; $gbName = $row['gbName']; $gbComment = nl2br($row['gbComment']); $display_entry .= "$gbID:<BR><B>Posted on: </B>$gbDate <B>IP: </B>Logged<BR><B>Posted by: </B>$gbName<BR><B>Personal website: </B>$gbURL<BR><B>Comment: </B>$gbComment<BR><BR>"; } $sql = "SELECT last_insert_id($gbID) FROM $table_to_look_for"; $How_many_entries = @mysql_query($sql, $connection); // $How_many_entries = $How_many_entries / 5; echo "Entries: $How_many_entries<BR>"; etc....
About Mysql Reading And Newsgroups
I took quite elaborate SQL and SQL-admin courses at Oracle, but that was years ago. Have never since used SQL but for some extremely simple straightforward queries on single table db's. So while conjoins, inner and outer joins et cetera ring some bells, I wouldn't know how to tell one from the other anymore, let alone put them to good use. So I decided to check for some good reading material that starts from scratch but quickly picks up. I haven't really found a lot yet, my library has zip and I don't want to buy before I try or be sure its worth the cost. I am a rather quick learner I think, with a preference for visual support and try it yourself quiz-type quick snippets. If there is a choice in underlying OS, I prefer Linux to Win32. I also tried to find some good newsgroups, and while PHP has several, I can't find a good english (or dutch) ng on mysql (at least not on my isp-server). Do you peeps have some tips on good reading/study material and newsgroups to look for ?
PHP/mySQL Insert Into Statement With Auto Increment
When i use mysql from the linux command line it is just plain simple to add an row into a table, even with php this isn't a problem. But when the table has aan field with auto_increment php won't allow to insert a new row in the table. I'll get an invalid query back.. In don't understand how to insert a new row into a table with the auto increment. Btw this is also the primary key: Code:
Getting Form Info Into A Mysql Select Statement
I'd like to get user input from an html form into a mysql select statement. Here's where I'm stumped: $result = mysql_query("SELECT * FROM dept WHERE notes LIKE '%search-string%'",$db); I need to get the user's input into the '%search-string%' section, but I do not understand how to do this. I can hard-code a specific search string and it will work, but I want the users to be able to dynamically define the search-string. So, I created a basic html form and used the post method to grab their input, but now I can't insert that input into the mysql select statement. Any ideas? I think it should be easy, I just don't know how to do it. I've tried this: $result = mysql_query("SELECT * FROM dept WHERE notes LIKE '%$_POST["search"]%'",$db); But it doesn't work. Below is the form in html and the php file: <html> <title>Search Test</title> <head> </head> <body> <form action="search-db.php" method="POST"> <p>Enter Your Search: <input type=text name=search></p> <input type="submit"> </form> </body> </html> ----------------------------------------------------------- <html> <body> <?php $db = mysql_connect("localhost", "Anonymous"); mysql_select_db("computers",$db); $result = mysql_query("SELECT * FROM dept WHERE notes LIKE '%surplus%'",$db); echo "<table border=1> "; while ($myrow = mysql_fetch_array($result)) { printf("<tr><td><b>%s</b></td></tr> ", $myrow[notes]); } echo "</table> "; ?> </body> </html>
Reading Multiple Lines From Mysql
I made a phpscript to enter data into my database, all works fine. I've got a <textarea> where i enter for example the following text (without the qoutes): "Hi, my name is Joey, i luv scripting and online gaming. I live in belgium, lovely country but bad weather" the script enters that text into the table. Another script of mine queries the database for the text, but it outputs: "Hi, my name is Joey, i luv scripting and online gaming. I live in Belgium, lovely country but bad weather" It's just one strait line and not the block i entered. Anyone know how i fix that? It also happens when i input 2 word or more in a <input type=text>. The data is in the table but when i reinput it into an <input type=text> (for editing) it only inputs one word.
MySQL Prepare Statement Performance Bottom-neck
When doing mysql query (SELECT statements) in php, we often use prepare statement to prevent SQL injection. However, I just noticed that the prepare statements can SLOW the number of queries per second by a factor of 2 times (max). So are there any faster method that can prevent SQL injection, but has a better performance?
MySQL UNION: Only The First Select Statement Returns A Result.
I am attempting to join multiple select statements into a single query. However, I am not able to extract the result of any of the UNIONED selects. $query1 = mysql_query (" ( SELECT SUM(deposits) AS total_deposits FROM table1 ) UNION ALL ( SELECT SUM(withdrawals) AS total_withdrawals FROM table1 ) ") or die (mysql_error()); $result1 = mysql_fetch_array($query1); extract($result1); When I echo the results of the second select statement I get nothing. echo $total_withdrawals;
MYSQL CASE Statement Within PHP Syntax Or Correct Quoting ?
I'm trying to use a MySQL "CASE" statement within PHP to develop a conditional query. The query runs fine within from the MySQL command prompt with the "case" statements. And the PHP code works fine when I remove the lines that begin with "case". However when I run the query as listed below within my PHP code i get the following: [Fri Apr 20 22:15:24 2007] [error] [client 10.188.50.74] PHP Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /srv/www/htdocs/mysql-learn/acetrack-post.php on line 68, referer: http://webserver1/mysql-learn/acetrack-post.html < code snip > $query =" SELECT acetitle, tracking_no, aceamt, case when (To_days(curdate()) - To_days(create_date)) >= 90 Then pototalamt else "" end as "90past" , case when (To_days(curdate()) - To_days(create_date)) < 90 and (To_days(curdate()) - To_days(create_date)) > 30 Then pototalamt else "" end as "30-90past" FROM Purtable t LEFT JOIN acelog a ON ace=acenum WHERE ace='0220' GROUP by po ASC "; $result = mysql_query($query); < /code snip > Thanks in advance for any help.
Reading MySQL Data In A Form Field
i am in the process of building an admin page for a site. Most of my site data is being held in MySQL and being pulled using PHP. The problem I have is while trying to build an Admin form to change data in MySQL, I want to have the data that is currently in the table be automatically put into the form field, so they can see what they are changing before they change it, or so if they do nothing it keeps the same data in it. My code is as follows:
Problem Reading Data Out Of MySQL Db, PHP Variables
Below is part of a code I have for a database. While the database table is created correctly (if it doesn't exist), and data is input correctly into the database when executed, I have a problem when reading out the data into the PHP variables / array. It should be displaying the information out in the following way, using the PHP array: n_date, n_headline, n_summarytext, n_fulltext But what actually gets displayed is the data for: n_date, n_headline, n_summarytext So the "n_fulltext" is not displayed, but the echo'ed text preceeding it "Full text:" is displayed, but it is not reading the information out of the variable. I have checked that there is information input in this field in the db, and it is there.....
Reading And Displaying A Date From A MySql Database
I've just started using php, and although I am very impressed by it, there are some things with which I am confounded! What I'm trying to do is read in a Date from a mySql database and then display it on screen (the Date is in the usual yyyy-mm-dd format). If I use SQL on phpadmin SELECT Date FROM details WHERE details.Name = "Paul Lee" LIMIT 0 , 30 The result comes up 2005-01-01, so this seems to work. But if I use the following: $db = mysqli_connect("localhost","root",""); @mysqli_select_db($db, "personnel") or die ( "Unable to select database" ); $query = 'SELECT Date FROM details WHERE details.Name = "Paul Lee" LIMIT 0, 30' $result=mysqli_query($db, $query); echo "<br>"; echo $result; mysqli_close($db); I get "Object id #2" displayed on screen. I have tried to use the explode function to separate the months, year and day using the "-" as a delimeter, but this doesn't work, and I can't seem to get the other php date/time functions to work either.
Reading Rfrom Mysql & Writing To Txt File
I am trying to write a simple script (see below) that connects to a database, pulls out information on each row, and puts that information on each row into a variable before printing it into a text file. This is the script: Code:
Reading From Text File And Storing In MySQL
I have a text file consist of 10 digit phone numbers one number per line like this: 5553332244 5553332244 5553332244 5553332244 etc… How do I read a text file line by line and populate the data into an array to store it into a MySQL database? My database is below:
Update Statement Causes Mysql Varchar Field To Be Set To Empty String
I have come across a problem that has me baffled. I am using PHP with MySQL 4.1.14. Whenever I execute an update statement against a specific table, some of the varchar fields do not get set to the new values, but get set to empty strings instead. I have simplified the code down to updating a single column in the table, but the same results happen when updating just the single column. Here is the stripped down code which causes the problem: $queryString = "UPDATE REGISTRATION SET passwd = '$pass'' WHERE id = 388"; $db = mysql_connect("hostname", "user", "pass"); mysql_select_db("CUSTOMER", $db) or die(mysql_error()); mysql_query($queryString, $db) or die(mysql_error()); Printing the query string after executing mysql_query shows the following query: UPDATE REGISTRATION SET passwd = 'test' WHERE id = 388 This query updates the column successfully when run directly through phpMyAdmin. When run through PHP using the code above then column is set to an empty string value. There is no error returned if I call mysql_error() nor is there any unusual info returned from mysql_info() (other than it telling me that 1 row was affected). Does anyone have any ideas what the underlying problem is on this one? Could be an attribute of the database table or columns that would cause this behavior? I have racked my brain for a while over this problem.
MYSQL Query Script To Reading From A Text File
Im having a hard time converting the following tree menu script to read nodes from a text file, rather then a database. This script works perfectly and is exactly what i am looking for, however it relies on query's from a MySQL database (I don't know how to set one up is the real problem). I would like to keep the feature where you can pass a parameter through the script and its expands the corresponding folder. Code:
If Statement Construction Within An Echo Statement
I have a form that is being used to "update" user info and I need the information to be pulled from the users table. In order to get the variables into the form, I am echoing it in and using an mysql array to place them into the form. at the t-shirt size part of the form the code is as follows ....
Reading An Array Of Records From MYSQL Then "Save As" Them Back As Copy
Hi all, Ok here is what I want to do then I will show you what I have. I have some records in a MySQL DB that I want to store in an array and then immediately copy them back where the only thing that would change would be one field - the date. So here is my table: ------------------------------------- |userName | date | value | -------------------------------------- | theDano | 200005 | 123 | -------------------------------------- | theDano | 200005 | 345 | -------------------------------------- | theDano | 200004 | 678 | -------------------------------------- | joeUser | 199908 | 897 | --------------------------------------- So if I am querying for the user "theDano" on a specific date (format yyyymm) in this case 200005 (year 2000 month of May) Here is my array to query all records to fullfill this request: if ($update=="future") { if ($month!="01") { $db = mysql_connect("localhost", "dbuser"); if($db) { mysql_select_db("dbName",$db); $result = mysql_query("SELECT * FROM tableName WHERE userName = '$userName' AND date = '$date' ORDER BY value DESC ",$db); if ($result) { $num=mysql_numrows($result); $i=0; while($i < $num) { $userName = mysql_result($result,$i,"userName"); $value = mysql_result($result,$i,"value"); echo "<tr>"; echo "<td width=Ê×'>" . $userName . "</td>"; echo "<td width=ï`'><div align='right'>" . $value . "</div></td>"; echo "</tr>"; ++$i; } } } } } Now I want to take the array of records queried which was: | theDano | 200005 | 123 | -------------------------------------- | theDano | 200005 | 345 | and copy them to look like this back into the database: | theDano | 200006 | 123 | -------------------------------------- | theDano | 200006 | 345 | so you can see that the only thing changed was increasing the month by one. Would seem simple to most but I am having a tough time wirting the code to read the array and increase each date value by "1". Thank you in advance for anyone that replies. ) Dano
If Or Switch?
I'm having a hard time deciding whether to use an if statement or switch statement. wouldn't it make more sense to always use a switch statement when testing for multiple condiitons? i dont see what the difference is other than the switch statement breaking the process and thus saving memory. someone please explain!
Trying To Use A Here Doc Within A Switch
I'm trying to use here docs within a switch to output html. The code below works (i.e. prints a Foo1 headline below my tab graphic) but if I take out the comments and use the entire switch statement I get a parse error. I've tried to simplify it down to the bones but can't get it much simpler than this... Can anybody spot my error .....
SWITCH
This code works if the IP address is a match, BUT if it is not a match why does this code not use the DEFAULT switch? Code:
Telneting Into A Switch
I would like to telnet into a switch and run commands which displays the configuration details which I need to capture in a web page and display it. I need to know how to telnet into a particular ip and then run a command using php?
Problem With 'switch' And Zero
I'm trying to use a switch construct to compare the result of a form with a list of known values and display a different page according to the submitted string. The problem is that some of the answers I need to check for are strings of the character zero of varying length: E.g. <?php switch (trim(strtolower($_POST['answer']))): case "abc": case "xyz": case "0": include 'close.htm' break; case "0000000000": include 'vclose.htm' break; default: include 'sorry.htm' endswitch; ?> What happens is that a submission consisting of a string of any number of zeroes cause the first page to be displayed rather than the second. I thought this was because it was treating it as an integer 0, so I tried putting (string) casts all over the place,
Switch My Case
I haven't used switch before, so I thought I'd give it a go. But I ran into some trouble. The case is like this: I have a search results page where, depending on the no of hits, different texts should be printed. Perfect for switch I thought, but I need to use a different range for each case. Some code: // connect and query code not included... $numrows=mysql_num_rows($result); switch ($numrows) { case $numrows==0: $traff='Do it again...' break; case $numrows==1: $traff='Great!!' break; case $numrows<=25: $traff='Should be here somewhere...' break; case $numrows<=50: $traff='a little too many...' break; case $numrows>51: $traff='Whoa!!!' break; default: $traff='OK!'} echo "$numrows $traff"; So I always know how many hits I get and this works except when I get no hits. The value of $numrows shows 0, but $traff shows 'Great!!'Why? Or am I doing this wrong?
|