mysql_get Advanced?

4 posts by 2 authors in: Forums > CMS Builder
Last Post: December 20, 2012   (RSS)

By Perchpole - December 19, 2012 - edited: December 19, 2012

Hello, All -

I'm looking for a small bit of code which will pull out a row from a table and which works a little like mysql_get.

mysql_get works like this:

mysql_get('table' match)


What I need is something more specific:

mysql_x('table' field, match)


Does such a thing exist?

:0)

Perch

By Dave - December 19, 2012 - edited: December 19, 2012

Hi Perch,

So you just want a specific field only?

You can do it with two lines of code:
$record = mysql_get($tableName, null, array("username" => "dave")); // get first record where: username = dave
$city = @$record['city'];


Of you can use a help function we made called array_value() that lets you retrieve the value of a specific array element by name or number. Like this:
$city = array_value( mysql_get($tableName, null, array("username" => "dave")) , "city");

Let me know if either of those will work for you. Cheers!
Dave Edis - Senior Developer
interactivetools.com
Hi, Dave -

Thanks for this. What I am trying to do is call a row from a table based on the data created in a foreach loop.

The loop calls each category. What I'm trying to do is then call the first record (from the record table) which is assigned to that category. I asume it will work something like this:

<?php foreach($category as $thisCat): ?>

<?php $thisRow = mysql_x('record', $record['category'] == $thisCat['num']); ?>

<?php echo $thisRow['title'] ?>
<?php echo $thisRow['etc...'] ?>

<?php endforeach ?>


I need to pull out the entire row so that all of the data is accessible - even uploads.

Make sense?

:0)

Perch