Jump to content

Problem with Temporary Tables


latemodern

Recommended Posts

Hi There,

 

I am trying to use a temporary table but it doesn't appear to be working.

 

//create the temporary table

 

$temp = "CREATE TEMPORARY TABLE temp (

id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,

user_id SMALLINT UNSIGNED NOT NULL,

name VARCHAR(50) NOT NULL,

gender VARCHAR (10) NOT NULL,

photo_file VARCHAR(30),

minbeds SMALLINT(6) NOT NULL,

maxbeds SMALLINT(6) NOT NULL,

minrent SMALLINT(6) NOT NULL,

maxrent SMALLINT(6) NOT NULL,

smoker VARCHAR(20),

smokingmix VARCHAR(20),

studentmix VARCHAR(20),

minage SMALLINT(6) NOT NULL,

maxage SMALLINT(6) NOT NULL,

email VARCHAR(50),

phone VARCHAR(20),

description TEXT,

stu VARCHAR(20),

gend VARCHAR(20),

comp_score SMALLINT,

PRIMARY KEY (id)

)";

 

if($tempresult = mysql_query($temp)){

echo 'Result';

}else{

echo mysql_error(). $temp;

}

 

 

//Insert temporary values

 

$temp_insert = "INSERT INTO temp (user_id, name, age, gender, photo_file, minbeds, maxbeds, minrent, maxrent,

smoker, smokingmix, studentmix, minage, maxage, email, phone, description, stu, gend, comp_score)

VALUES ('$user_id', '$name', $age, '$gender', '$photo_file', $minbeds, $maxbeds, $minrent,

$maxrent, '$smoker', '$smokingmix', '$studentmix', $minage, $maxage, '$email', '$phone', '$description',

'$stu', '$gend', $comp_score)";

 

 

//not sure if i need this bit

 

$temp_insert_result = mysql_query($temp_insert);

 

//then test whether there was a result

 

$megaquery = "SELECT name FROM temp";

if($megaresult = mysql_query($megaquery)){

echo $megaquery;

while($megarow = mysql_fetch_array($megaresult, MYSQL_ASSOC)){

echo '<p>'

.$megarow['name'].

'</p>';

}

} else {

echo mysql_error();

echo $megaquery;

}

 

I get the following text on the page (as you would expect) but nothing else. Have the queries worked? I was expecting to get a list of names. The variable values that I am trying to insert into the table aren't empty and they appear if I echo them before I try to insert them in the temporary tabel

 

Am I doing something wrong?

 

Thanks a lot

 

Chris

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.