FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Manually create array that matches mysql_fetch_array
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Manually create array that matches mysql_fetch_array [message #179729] Thu, 29 November 2012 08:51 Go to previous message
jwcarlton is currently offline  jwcarlton
Messages: 76
Registered: December 2010
Karma:
Member
In my script, I'm potentially creating information to insert in to MySQL (based on a few variables), then later in the script I'm SELECTing the same data back out of MySQL. Like this:

if ($_GET['whatever']) {
$query = "REPLACE INTO...";
mysql_query($query);
}

$s_query = "SELECT ...";
$sql = mysql_query($s_query);

while (list(...) = mysql_fetch_array($sql)) {
// show data
}

This is obviously redundant, though, so I'm trying to find a way to create $sql in the first if() statement, so that the SELECT statement isn't necessary if it already exists.

Like:

if ($_GET['whatever']) {
$query = "REPLACE INTO...";
mysql_query($query);

$sql = ???;
}

if (!$sql) {
$s_query = "SELECT ...";
$sql = mysql_query($s_query);
}

while (list(...) = mysql_fetch_array($sql)) {
// show data
}


I know that I could create a regular array, then after the conditional SELECT statement use a loop to push the data in to the array. But what I'm curious about is if it's possible to just manually create the same type of array as mysql_query()?
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Query a Array Field in MySQL
Next Topic: Experience Web and Smartphone designer required
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 09:17:58 GMT 2024

Total time taken to generate the page: 0.04626 seconds