Welcome, Guest. Please login or register.
Did you miss your activation email?
February 13, 2012, 03:50:48 AM

Login with username, password and session length
Search:     Advanced search
Wollen Sie dem WebsiteBaker Team beitreten?
Nähere Informationen finden Sie unter hier und auf unserer neuen Webseite.
149700 Posts in 21103 Topics by 7538 Members
Latest Member: ionline
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: help understand database row fetching  (Read 305 times)
Availor

Offline Offline

Posts: 225



« on: May 15, 2010, 02:15:18 PM »

I've started learning php since not being able to fix a minor problem is annoying...

I started from the very basic, trying to pull the first image from the gallery module from it's database:

Code:
<?php
$result 
mysql_query("SELECT title FROM mod_gallery_images WHERE image_id='4'"$database);
$myrow mysql_fetch_array($result);

echo 
$myrow['title']
?>

The idea (eventually) is to pull the latest (anything) from a specific module, like recent images, recent news etc...

Eventhough it works fine on my local server (wamp) id doesn't work on WebsiteBaker database.

If anyone can help me understand how to fetch rows (in this example title)...
I've opened some of the modules like anynews and anytopics but they had too much code with too many variables so I got confused.

It seems to be like an easy task fetching some data from a certain table...
Logged
DarkViper
Development Team
*****
Offline Offline

Posts: 1053


« Reply #1 on: May 15, 2010, 03:24:49 PM »


Code: (try this)
<?php

$title 
$database->get_one'SELECT `title` FROM `'.TABLE_PREFIX.'mod_gallery_images` WHERE `image_id` = 4' );

echo ( !
is_null($title) ? $title '' );

?>

For all other problems: RTFM
Logged

Anleitungen lesen und selber nachdenken ist anstrengend...  Da lass ich doch lieber andere für mich denken...

In 1984:  Nineteen Eighty-Four is a unrealistic utopia!!
In 2012:  Nineteen Eighty-Four is a little piece only of our reality!!
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1680



« Reply #2 on: May 15, 2010, 03:27:24 PM »

Hi,

First, you did not define $database...

Take a look at this examples:
Code:
if($res = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'")) {
    if($res->numRows() > 0) {
        $page = $res->fetchRow();
         echo $page['link'];
   }
}

if($res = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts WHERE active = '1'")) {
    if($res->numRows() > 0) {
        while($post = $res->fetchRow()) {
            echo $post['title'];
        }
    }
}

cheers
Logged

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
Availor

Offline Offline

Posts: 225



« Reply #3 on: May 15, 2010, 04:48:52 PM »

@DarkViper: Thanks it worked. I already went through the developer guide didn't understand it....

@crnogorac081:
It seems to give the page path, as a loop (?) - to fetchrow() while the table is more than 0... ?

Anyway thanks for the support I'll try figuring this out, I have some more php turorials to learn from


Logged
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!