Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Good or Bad idea?


  • Please log in to reply
30 replies to this topic

#25 BlaineSch

BlaineSch

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1559 posts

Posted 22 August 2009 - 03:03 PM

Since the fetch_assoc and fetch_array both only give me one array at a time, I cannot find a way to combine them, thus my method I think cannot be changed to be more efficient and kept to return one big array.

Do you know how I can make it an array if it only gives me one result at a time?
  • 0

#26 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 22 August 2009 - 03:03 PM

As you have it: $row[name] and $row[data] as well as $_SERVER[REMOTE_ADDR] PHP looks in the memory stack for for the constant definitions name, data, and REMOTE_ADDR and realizes there they aren't defined anywhere. It then says to itself "wtf is this noob doing" and realizes you actually meant $row['name'], $row['data'], $_SERVER['REMOTE_ADDR'].

What would happen if you had the following situation?

define('name', 'john');
//...
echo $row[name]

  • 0

#27 BlaineSch

BlaineSch

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1559 posts

Posted 22 August 2009 - 03:05 PM

Ahhh I see what you mean!

That was just me being lazy =) I shall fix it since you bring up a very good reason why I should not do this.
  • 0

#28 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 22 August 2009 - 03:08 PM

As for your other issue, I see no reason why you cant just do:

                } else {
$rows = $query->fetch_assoc();
}


Although its not an array, it is the actual resource. Using the foreach should still be able to loop through the values.
  • 0

#29 BlaineSch

BlaineSch

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1559 posts

Posted 22 August 2009 - 03:17 PM

The only way I could get it to work is to return the entire $query array, then do the fetch_assoc in my own code which is not that bad :D
                } else {
$rows = $query;
}

	$query = $mysql->query("SELECT * FROM `global`", 0);
while($row = $query->fetch_assoc()) {
$data[$row['name']] = base64_decode($row['data']);
}

  • 0

#30 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 22 August 2009 - 03:20 PM

I think that is a better alternative. You are trying to encapsulate too much functionality in a single method.
  • 0

#31 BlaineSch

BlaineSch

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1559 posts

Posted 22 August 2009 - 03:32 PM

Now it should be fairly easy to update too! define $mysql at the top, then do a str replace on the file "mysql_" to "$mysql->" I may have to do some special things for the second param in query() though although it is set default to 0
  • 0




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download