Re: [PHP-DB] SELECT syntax

2011-10-13 Thread Karl DeSaulniers

Or something like this?
SELECT * FROM `Bible_trivia` WHERE answer=`answer`;
Then match the results to trivia_answer_1 in php to see if correct.

if($trivia_answer_1 == $results) {
... do this
}

or a switch

switch ($results) {
case $trivia_answer_1:
... do this
case $trivia_answer_2
... do this

Best,
Karl

On Oct 12, 2011, at 11:04 PM, Amit Tandon wrote:


SELECT `trivia_answer_`answer`` FROM `Bible_trivia`


Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] SELECT syntax

2011-10-13 Thread Karl DeSaulniers

Heh,
Thanks Karthik. Not my post.. :)
But your solution looks dead on..

Here you go Ron. Try this one.

Best,
Karl


On Oct 13, 2011, at 2:42 AM, Karthik S wrote:


Try this,

select
CASE answer
 when 1 then trivia_answer_1
 when 2 then trivia_answer_2
 when 3 then trivia_answer_3
 when 4 then trivia_answer_4
END as trivia_answers
from bible_trivia_table

On Thu, Oct 13, 2011 at 1:02 PM, Karl DeSaulniers k...@designdrumm.com 
 wrote:

Or something like this?
SELECT * FROM `Bible_trivia` WHERE answer=`answer`;
Then match the results to trivia_answer_1 in php to see if correct.

if($trivia_answer_1 == $results) {
... do this
}

or a switch

switch ($results) {
   case $trivia_answer_1:
   ... do this
   case $trivia_answer_2
   ... do this

Best,
Karl


On Oct 12, 2011, at 11:04 PM, Amit Tandon wrote:

SELECT `trivia_answer_`answer`` FROM `Bible_trivia`

Karl DeSaulniers
Design Drumm
http://designdrumm.com



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Karl DeSaulniers
Design Drumm
http://designdrumm.com



[PHP-DB] Odd MySQL Problem...

2011-10-13 Thread Jason Pruim
Hey everyone,Have a weird issue that I can't seem to figure out...Using PHP to insert phone numbers into the site... I have the Area Code,  Exchange, and then dynamically create the last 4 digits... Once it's inserted it's dropping the leading zero's... Here's some samples:Copied from phpMySQL:EditInline EditCopyDelete2122000681EditInline EditCopyDelete2122001682EditInline EditCopyDelete2122002683EditInline EditCopyDelete2122003684EditInline EditCopyDelete2122004echoed output from PHP:SQL: INSERT INTO phonesite (areacode, exchange, subscriber) VALUES(212, 200, 0001)SQL: INSERT INTO phonesite (areacode, exchange, subscriber) VALUES(212, 200, 0002)Actual PHP code:?PHP//  ini_set('display_errors', 1);//error_log(-1);set_time_limit(0);//set_time_limit("120");include "includes.php";include "databaseabstraction.php";include "authentication.php";dbconnect("localhost", "XX", "XX", "XX")or die("Unable to connect: " . mysql_error());function number_pad($number,$n) {return str_pad((int) $number,$n,"0",STR_PAD_LEFT);}if (($handle = fopen("newyorktest.csv", "r")) !== FALSE) { while (($data = "" 1000, ",")) !== FALSE) {print_r($data);   foreach( range(0, ) AS $n) {   //echo "BRDATA: " . $data[2] . "BR";  $padded_number = number_pad($n, "4");  $sql = "INSERT INTO phonesite (areacode, exchange, subscriber) ";  $sql .= "VALUES({$data[1]}, {$data[2]}, {$padded_number}) ";  //mysql_query($sql) or die("Didn't insert you dumb ass FIX IT NOW CLOWN " . mysql_error());echo "SQL: " . $sql . "BR";  } } echo "File Bitches!"; fclose($handle);}?Any ideas on what I'm missing?Thanks everyone!
Jason Pruimli...@pruimphotography.com




Re: [PHP-DB] Odd MySQL Problem...

2011-10-13 Thread Karl DeSaulniers
Its looking for an integer not a string for the number of characters.  
I think..


Eg : number_pad($n, 4);


On Oct 13, 2011, at 9:53 PM, Jason Pruim wrote:


number_pad($n, 4);



Best,

Karl DeSaulniers
Design Drumm
http://designdrumm.com