GingerRobot
Staff Alumni-
Posts
4,082 -
Joined
-
Last visited
Everything posted by GingerRobot
-
Ok, so I've run the code above with only two modifications - an included database connection and an echo of a table tag. Giving code: <?php include('test_db_connection.php'); $query = "SELECT id FROM cerebra ORDER BY id"; $result = mysql_query($query) or trigger_error(mysql_error(),E_USER_ERROR); echo '<table>'; if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 3; while($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; // make sure we have a valid product if($id != "" && $id != null) echo "<td>$id</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } ?> Using the structure: CREATE TABLE `cerebra` ( `id` int(2) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `cerebra` -- INSERT INTO `cerebra` (`id`) VALUES (1), (2), (3), (4), (5), (6), (7), (, (9), (10); I receive the expected 3 column table layout. E.G. No errors. I can't see anything version specific in the above code.
-
The problem is that you've named the function and the variable with the same name. Try: <script type="text/javascript"> function timesbytwo() { //get the value from the text field var current = document.getElementById("current").value; //print to the div document.getElementById("preview").innerHTML = current*2; } </script> <form> <input type="text" onKeyup="timesbytwo()" id="current"/> <div id="preview"></div></form>
-
I notice that you assign the query to $query, but then execute the query $sql. That would give you an error, but not the same one we had previously. I can only guess that you've not told us the error has changed. If you run just this code and nothing else: <?php $query = "SELECT codename FROM cerebra ORDER BY codename"; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 3; while($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; // make sure we have a valid product if($codename != "" && $codename != null) echo "<td>$codename</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } ?> Do you still get a syntax error? If you do, I give up. You should get an error - something related to not having a database selected. If you get that error, then try adding in your includes and see whta happens.
-
Use ctype_digit()
-
I'm not quite sure how you're getting that error, that shouldn't be caused by that line. I do notice that you've got a stray opening brace here though: while($row = mysql_fetch_assoc($result)){//This one is unclosed. I suspect caused by a copy/paste mistake //here's the key. Use a while loop to repeat through the code { Try: <table cellspacing="3" cellpadding="3"> <?php $query = "SELECT codename FROM cerebra ORDER BY codename"; $result = mysql_query($query) or die("There was a problem with the SQL query: " . mysql_error()); if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 3; while($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; // make sure we have a valid product if($codename != "" && $codename != null) echo "<td>$codename</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i < $max_columns) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; } ?> </tr> </table>
-
How do I generate 4 different random numbers?
GingerRobot replied to eugeniu's topic in PHP Coding Help
papaface: what guarantees that those random numbers are different? -
The problem is that you're while statement assigns one variable to another. There's no comparison going on. Since it's always able to assign, the loop is always true. Basic structure of a while loop: while($row = mysql_fetch_array($result)){ $var = $row['var']; echo $var.'<br />'; } On a site note, you should really consider naming your variables something a bit more descriptive.
-
Is this a joke? Make what work? What doesn't work? What would you like it to do?
-
proportional thumbnail - width and height
GingerRobot replied to felipeebs's topic in PHP Coding Help
To resize proportionally X1/Y1 = X2/Y2 Therefore, if you know X2 (e.g. the width is greater than height, so width = 800), then Y2 = Y1/X1 * X2 - by rearranging the above formula Conversely, if you know Y2, then X2 = X1/Y1 * Y2 -
If you're outputting something to the screen but still able to use the header() function without errors, you'll have output buffering enabled. As for why you should exit; well, if you're changing location then you don't want the rest of the script executed do you?
-
I've made several observations that indicate that this is normal behavior for the Media Direct button - my recommendation to the owner of the laptop was to pry the cover off and remove the actual button on the circuitry. A teeny flat-head screwdriver later, the Media Direct button was absolutely useless. The owner reports no negative side effects, and is thrilled with not having to reinstall the OS every time she misses and presses the wrong button. Interestingly, my seems to be fine. When switched off, the button boots the Media Direct thing When in Ubuntu, i have it set to launch Rhythmbox. And when in vista, it launches the Media Direct thing in vista.
-
Think I'd make money off a local hosting company?
GingerRobot replied to tibberous's topic in Miscellaneous
Reminded me of a news article i saw a couple weeks ago. Evidently i remembered incorrectly seeing as no-ones actually getting sued, but it's still rediculous: http://news.bbc.co.uk/1/hi/world/europe/7479758.stm -
[SOLVED] Include font and font size in php table tag
GingerRobot replied to rscott7706's topic in PHP Coding Help
Why don't you have a go and post if can't figure it out. Though, as you said earlier, it would be better to put your font styling in a separate CSS file. -
Why not use the serialize() and unserialize() functions?
-
[SOLVED] Include font and font size in php table tag
GingerRobot replied to rscott7706's topic in PHP Coding Help
Or try, as i posted, enclosing the string to be echoed in single quotes, so that double quotes may be echoed without escaping them. -
isset() is your friend. You also wouldn't want to be querying the database without validating your input. if(isset($_GET['pageid'])){ $pageid = mysql_real_escape_string($_GET['pageid']);//ought to be sanitizing your input. }else{ $pageid = 'home'; }
-
A blank page is usually caused because there's an error, but you have display_errors turned off. See if you can either enable this option, or check your error log.
-
[SOLVED] Stupid question about mysql_real_escape_string()
GingerRobot replied to JHolovacs's topic in PHP Coding Help
It's also the invention of the devil. Almost. -
[SOLVED] Include font and font size in php table tag
GingerRobot replied to rscott7706's topic in PHP Coding Help
So what's the problem? echo '<table id="board">'; -
I've read elsewhere that the media direct button can do an awful lot of damage. Apparently if it doesn't find the partition table the way it likes it, it wipes it out. Oops.
-
Think I'd make money off a local hosting company?
GingerRobot replied to tibberous's topic in Miscellaneous
Just check the TOS. There'll be a fair usage policy (How you can get away with calling something unlimited on the one hand, but saying it's subject to fair usage terms on the other i really don't know). Sometimes, this can turn out to be very low. -
That's because you shouldn't be storing multiple countries in one field. You should add a separate table containing a list of countries. If you're ever considering storing more than one piece of information in a field, you probably need to think about your structure and add a new table. This tutorial might be a good place to start to learn more.
-
Maximum Data you can store in a session object?
GingerRobot replied to libertyct's topic in PHP Coding Help
Why on earth would you wish to store that kind of information in a session? -
[SOLVED] Pass Select List Value via POST problems
GingerRobot replied to joshluv33's topic in PHP Coding Help
You need to give your options a value. It is that which is passed via POST, not the text shown in the drop down box. -
[SOLVED] Transferring data from a Mysql column to a php array...
GingerRobot replied to captainspi's topic in PHP Coding Help
You'll want something like this: $sql = "SELECT field FROM yourtable"; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); $array = array(); while($row = mysql_fetch_row($result)){ $array[] = $row[0]; } print_r($array);