-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
Why are you asking whether that will work or not? Just run it and find out.
-
well, I mean yeah, if your table name is a mysql reserved word, then you do need to use backticks around it (or better yet, choose a different table name, as that's poor coding), but that's not what would cause multiple rows to be updated.
-
hey...that's pretty cool, I'll have to remember that one
-
no... perhaps the problem is with your table structure. Perhaps you have your "date" column setup to automatically update to the current timestamp upon updating or something?
-
from a comment of sort() in the manual: http://www.php.net/manual/en/function.sort.php#75381 just slap an array_reverse() around the function call or modify the function to suit your needs.
-
Well you said in a previous post you had the table name stored in a variable somewhere...are you using that variable?
-
in order to update only 1 row, you need a where clause in your update query that specifies unique data for that row, like an id# or something, that's unique for that row. example: id name 0 adam 1 mark 2 julie 3 adam update table set name = 'james' where id = 0 would result in this: id name 0 james 1 mark 2 julie 3 adam
-
or wait... CREATE TABLE (ec1 VARCHAR(10) NOT NULL,ec2 VARCHAR(10) NOT NULL) needs to be CREATE TABLE tablenamehere (ec1 VARCHAR(10) NOT NULL,ec2 VARCHAR(10) NOT NULL) it looks like your problem is that $tablename in the query string is not being set.
-
okay well I have no idea how you have your db setup so create your table/columns directly in phpmyadmin through their menu and look at the outputted sql code it shows and compare the two and see how you need to modify it.
-
You don't need to use an array to pull or print info from a database, unless you plan on using the info later on after the loop. $sql = "select col1, col2 from table"; $result = mysql_query($sql); while ($info = mysql_fetch_row($result)) { echo "{$info[0]} {$info[1]} <br />"; } $info is an array but it's an array of the columns/data which isn't really relevant for ordering the rows.
-
echo $sql and insert the output directly into your db through phpmyadmin see if it gives you an error.
-
The unix timestamp wouldn't read 1st July 2000. It's an integer of the number of seconds since the unix epoch (January 1 1970 00:00:00 GMT). <?php $then = strtotime("1st July 2000"); $now = time(); $timepassed = $now - $then; $totaldays = $timepassed / 60 / 60 / 24; $years = (int) ($totaldays / 365); $days = $totaldays % 365; echo "$years years, $days days"; ?>
-
ob_start only works before the data is sent to the browser. If you're looking to have things change in "real time" as in, "123" is echoed in someone's browser and you're wanting some event to make it change to "456" in the browser, this is not possible with php alone, because php is parsed and executed on the server and then the results sent to the browser. If you want a "real time" solution you're going to have to go with javascript or ajax. Or just stick to clicking a link or form button and submitting and reprocessing/displaying as a whole with php.
-
The problem is that when you include rssparser.php the startelement function is declared but the error is saying that it's already been declared but I'm not seeing that in the code you provided so...is that code you provided being included somewhere else that perhaps also includes rssparser.php? My only clue to that is that you have another custom function rss_div_create that's not in your rssparser.php...
-
str_replace with only semi-known string that should be replaced
.josh replied to Nihilis's topic in PHP Coding Help
try using preg_replace instead of str_replace -
unix timestamp is time in seconds. $then = 1216757988; // previous timestamp (example number) $now = time(); // current timestamp $timepassed = $now - $then; // elapsed time in seconds 60 seconds in a minute 60 minutes in an hour 24 hours in a day 365 days a year $timepassed / 60 gives you how many minutes passed $timepassed / 60 / 60 gives you how many hours passed $timepassed / 60 / 60 / 24 gives you how many days passed $timepassed / 60 / 60 / 24 / 365 gives you how many years passed I mean, other than accounting for leap year... what exactly do you need help on? This is simple math...
-
Well it's really only a couple lines of code. Most of it is just commentary and the form you already made and my own extra code that I used to test it which you would have already had.
-
well technically that doesn't matter. if it's set it will equal 1. If it's not set, it won't be equal 1. Therefore doing <?php $SubscribeToNewsletter = $_POST['SubscribeToNewsletter']; if($SubscribeToNewsletter = "1"){ // mysql shit up in this bitchy, ya digg? } will work. Well, aside from him needing == not =. Also, since the posted value already equals 1, why make a new variable assigning 1 or 0? Simply use the original var. On the other hand, the posted var would need to be sanitized and your ternary inadvertently does that by assigning it 1 no matter what value was posted.
-
Well here's my take. It's longer than it should be because I made it all on 1 script (for testing) so you're gonna have to break it down into separate pages since your action target is a diff page, etc... <?php // if we have posted info (1+ checkbox checked) if ($_POST['Ec']) { // loop through each posted checkbox foreach($_POST['Ec'] as $key => $val) { // since the key starts at 0 but you want // the first one to be 1 we add 1 to it $key += 1; // string for the column names for create table query. // this assumes the columns are varchar(10). You can change // the col type here. If cols are not gonna be of the // same type, you're gonna have issues and you're gonna // want to rethink this whole variable column thing and // what data you're passing from the form $colNameCreateString .= "Ec$key VARCHAR(10) NOT NULL,"; // string for the column names for the insert query. $colNameString .= "Ec$key,"; // string for the column values for the insert query. $colValString .= "'$val',"; } // end foreach $_POST['Ec'] // chop the comma off at the end (side effect of foreach loop) $colNameCreateString = substr($colNameCreateString, 0,-1); $colNameString = substr($colNameString, 0,-1); $colValString = substr($colValString, 0,-1); // table name $tablename = "blah"; // connect to and select db (change to your info) $conn = mysql_connect('localhost','dbusername','dbpass') or trigger_error('sql: ', E_ALL); $db = mysql_select_db('dbname',$conn) or trigger_error('sql: ', E_ALL); // create the table using $colNameCreateString $sql = "CREATE TABLE $tablename ($colNameCreateString)"; $result = mysql_query($sql, $conn) or trigger_error('sql: ', E_ALL); // insert info into table using $colNameString and $colValString $sql = "INSERT INTO $tablename ($colNameString) VALUES ($colValString)"; $result = mysql_query($sql, $conn) or trigger_error('sql: ', E_ALL); } // if $_POST['ec'] // echo out the form echo <<<FORMENT <form action = '{$_SERVER['PHP_SELF']}' method = 'post'> Proposal:<input type='checkbox' name='Ec[]' value='E0010' checked='checked' /><br /> Conceptual Planning:<input type='checkbox' name='Ec[]' value='E0020' /><br /> Rezoning:<input type='checkbox' name='Ec[]' value='E0030' /><br /><br /> <input type="submit" value="Submit" /> </form> FORMENT; ?>
-
how about posting the code that is displaying "array"
-
if you make your checkbox name an array name = 'Ec[]' you can just implode $_POST['ec'] into a comma separated list and use that in your query.
-
How to dynamically change a table using checkboxes
.josh replied to firblazer's topic in PHP Coding Help
look into ajax for php/js interaction. but let's backup here a minute. Are you sure you want it to automatically delete by checking a checkbox? Checkboxes are meant for flagging multiple things. Maybe you mean to click multiple ones and then click a single delete button? You can do this by making a regular form with a regular submit button, no js required at all. -
did you check your spam/bulk email box?
-
Hehe, Python once again is the same. The same as in you need python installed to run a python script? I thought it was a full language that could compile standalone executables?