PDA

View Full Version : retreiving data via PHP and mySQL


Flash Gordon
07-10-2005, 10:03 PM
I was trying to help someone on here build an flash poll, but I'm stuck on how to retrieve the data. Here is what I have so far:

<?php
$reviews = $_GET['reviews'];
$transcriptions = $_GET['transcriptions'];
$interviews = $_GET['interviews'];
$IP = $_SERVER['REMOTE_ADDR'];


$user = "****";
$password = "*****";
$database = "*****";
$table = "results";
//--------------connenct to database
mysql_connect(localhost,$user,$password) or die("Could not connect");
mysql_select_db($database) or die ("Could not select the database");
//--------------insert the data into datbase
$query = "INSERT INTO " . $table . " VALUES('', '$reviews', '$transcriptions', '$interviews', '$IP')";
mysql_query($query);
//-------------get data from database
$reviews = "SELECT `reviews` FROM `results`";
$transcriptions = "SELCET 'transcriptions' FROM 'results'";
$interviews = "SELECT 'interviews' FROM 'results'";

$reviewsResults = mysql_query($reviews);
$transcriptionsResults = mysql_query($transcriptions);
$interviewsResults = mysql_query($interviews);
//-------------display results of data
//mysql_fetch_row()
//mysql_fetch_array()
//mysql_fetch_assoc()
//mysql_fetch_object()
//mysql_result()
Right now there are contents in $reviews, $transcripts, and $interviews but I don't know how to get the data to make it manageable. I'm guessing I need to use one of the last several functions I listed in the php code above, but I'm stuck. Any help? I'd like to just put the answers in a normal array.
Each variable ($reviews, $transcripts, and $interviews) has two options: 'yes' or 'no'. I eventually want to seperate them also, but that shouldn' be a problem once I get the data to where I can work with it.

Thanks
FG
--------------------------
The info is not need, just a little somthing extra incase I didn't explain it well
I'm trying to get the contents of the database. which looks like this
id--reviews--transcriptions--interviews--IP (used to see if they have already voted)
0 yes yes no xxx.xxx.
1 no no yes xx.xx.
2 yes no yes xx.xx.
etc.................

xxlm
07-11-2005, 12:08 AM
so you want to display this in a php page and would like to manage them...

just use

<?php
$myquery= "SELECT * FROM `results`";

while ($myRecord = mysql_fetch_array($myquery)) {
?>
<form action="yourprocessingphpfile.php">
<input name="idreviews" value="<?=$myRecords['reviews'];?>" />
<input type="submit" vlaue="send" />
</form>
<?php
}
?>


It's a basic example.
What you could do is making combobox that submiting the form onChange

Anyway I hope it's what you're looking for...

Cya

xxlm
07-11-2005, 12:11 AM
Else I'm not with cyan.
Kicks his ass sometime... To show who is the master... :D

Flash Gordon
07-11-2005, 02:37 AM
Thanks but I could get anything to happen with that code. I modified it a bit to:
//-------------get data from database
$myquery = "SELECT * FROM 'results'" or die(mysql_error());
if ($myquery) {
echo "queried database";
}
while ($myRecord = mysql_fetch_array($myquery)) {
echo $myRecord['reviews'];
echo "<br>";
}
echo "connection closed";
I a don't see anything on the screen from the while loop, just my inserted echos.

Also, I'm not trying to make a form, but 1) get data from the database 2) Store it in an manageable array 3) send that vaule to flash 4) and show poll results.

Thanks for your help. Much appreciated.

CyanBlue
07-11-2005, 02:53 AM
Can you zip up the sample file along with the database structure??? I am no good at this MySQL stuff unless I dip my hands dirty... :D

boyzdynasty
07-11-2005, 03:03 AM
//-------------get data from database

// Why do you have 'or die(mysql_erro()'...
// Should only be $myquery = "SELECT * FROM 'results'";

$myquery = "SELECT * FROM 'results'" or die(mysql_error());

// And you don't need this if statement here
if ($myquery) {
echo "queried database";
}


// if there were rows retrieved, this while statement condition is true!
while ($myRecord = mysql_fetch_array($myquery)) {
echo $myRecord['reviews'];
echo "<br>";
}
echo "connection closed";

Flash Gordon
07-11-2005, 03:12 AM
Here are all three (fla, php, txt of database) files attached:
EDIT: The "real" database is below.

Flash Gordon
07-11-2005, 03:19 AM
here is the database structure redone. The one in the first post is an txt extention; this on is an sql extention.

Also, included is the MX version of the fla.

Thanks for all the help guys.

xxlm
07-11-2005, 03:31 AM
OOOooooops... lol :D
Just make a string like

$poll= "";
while ($myRecord = mysql_fetch_array($myquery)) {
$poll.= "&".$myRecord['id']."|".$myRecord['reviews']."|".$myRecord['transwription']."|".$myRecord['interviews']."|".$myRecord['ip'];
}
echo $polls


Then in your fla parse your data using onData and not onLoad.
Search the forum for some example... ;)

C ya

Flash Gordon
07-11-2005, 03:49 AM
Urgh :(
using this code:
$myquery = "SELECT * FROM 'results'";
if ($myquery) {
echo "queried database";
}

$poll= "Hello World";
while ($myRecord = mysql_fetch_array($myquery)) {
$poll.= "&".$myRecord['id']."|".$myRecord['reviews']."|".$myRecord['transcriptions']."|".$myRecord['interviews']."|".$myRecord['ip'];
}
echo "$poll";
I get this result queried databaseHello World
Could it be my PHP and musql is mess up?

PHP Version 4.3.4
MySQL Support enabled
Active Persistent Links 0
Active Links 0
Client API version 4.0.17
MYSQL_MODULE_TYPE external
MYSQL_SOCKET /tmp/mysql.sock
MYSQL_INCLUDE -I/usr/local/include/mysql
MYSQL_LIBS -L/usr/local/lib/mysql -lmysqlclient

xxlm
07-11-2005, 04:05 AM
here is the php file working

<?php
$reviews = $_GET['reviews'];
$transcriptions = $_GET['transcriptions'];
$interviews = $_GET['interviews'];
$IP = $_SERVER['REMOTE_ADDR'];


$user = "root";
$password = "";
$database = "poll";
$table = "results";
//--------------connenct to database
mysql_connect(localhost,$user,$password) or die("Could not connect");
mysql_select_db($database) or die ("Could not select the database");
//--------------insert the data into datbase
$query = "INSERT INTO " . $table . " VALUES('', '$reviews', '$transcriptions', '$interviews', '$IP')";
mysql_query($query);
//-------------get data from database
$myquery = mysql_query("SELECT * FROM results") or die(mysql_error());
$poll= "";
while ($myRecord = mysql_fetch_array($myquery)) {
$poll.= "&".$myRecord['id']."|".$myRecord['reviews']."|".$myRecord['transcriptions']."|".$myRecord['interviews']."|".$myRecord['ip'];
}
echo $poll;
//-------------close connection to database
mysql_close();
?>

Flash Gordon
07-11-2005, 04:15 AM
:)

Thank you.

xxlm
07-11-2005, 05:02 AM
you're welcome...
Now check for onData and parsing...

C ya

;)

CyanBlue
07-11-2005, 12:32 PM
Good job, xxlm... :)

xxlm
07-11-2005, 12:58 PM
Héhé...
Thx cyanblue.

Glad to have a "rap on the shoulder" from you (I hope it's the right term in english too lol, I just want to say thx for the "good job" ;) )