i can't get my PHP/MySQL to work

Discussion and education for beginner / novice programmers interested in embarking on the development process to take advantage of the extensible nature of the Joomla! CMS.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Forum rules
Post Reply
-ronin-
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Feb 26, 2008 1:39 am
Contact:

i can't get my PHP/MySQL to work

Post by -ronin- » Tue Mar 04, 2008 6:42 am

I'm using Joomla! 1.5 and I'm still new to it, basically. Also, I would still consider myself a beginner to PHP/MySQL. So, I have a website that I built myself (http://africanmyspacelayouts.com/) and I want to recreate that exact same site with the exact functionality in Joomla.

here's the code I've been trying to get Joomla to execute, via IncludePHP plugin :

Code: Select all

<?php
$option['driver']   = 'mysql';            // Database driver name
$option['host']     = 'localhost';    // Database host name
$option['user']     = '<MY USERNAME>';       // User for database authentication
$option['password'] = '<MY PASSWORD>';  // Password for database authentication
$option['database'] = '<MY DB NAME>';      // Database name
$option['prefix']   = '';             // Database prefix (may be empty)

$dbh = & JDatabase::getInstance( $option );
$category = "Art";
$result = mysql_query("SELECT * FROM `#_layouttable` WHERE `category` = '{$category}' ORDER by name;", $dbh); 
$dbh->setQuery($result);
$name = $dbh ->loadResult();
                $myrow = mysql_fetch_array($name);
                ?>
                            
              <table align="center" cellspacing="10" class="categories"><!-- start table class categories -->              
              <?php
              do
              {
                printf("<tr>
                  <td class=\"layoutpic\">
                    <a class=\"layoutnamelink\" href=\"preview.php?name=%s\" target=\"preview\" title=\"%s Layouts\" >%s<br />
                    <img src=\"../images/%s\" /><br />
                    <div align=\"center\">Preview this African MySpace Layout</div></a>
                  </td>
                  </tr>", $myrow["name"], $myrow["name"], $myrow["name"], $myrow["pic"]);
              }while($myrow = mysql_fetch_array($resultcategory));
                ?>
            </table><!-- end table class categories -->              
Here's the error I get when I reload my Joomla frontpage:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\xampp\htdocs\joomla2\myincludes\categs.php on line 14

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\joomla2\myincludes\categs.php on line 17

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\joomla2\myincludes\categs.php on line 31

Please help me.

igrimpe
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Wed Feb 20, 2008 8:59 am

Re: i can't get my PHP/MySQL to work

Post by igrimpe » Tue Mar 04, 2008 10:20 am

First of all: I do not have any _layouttable in my Joomla 1.5 DBs ...

And you are mixing PHP-MySQL with Joomla classes. You either use native mysql_ commands or the J! classes, but not both.
And if you query a text field, you need to enclose the string in brackets (therefore your query would fail anyway)
And if you have a function (mysql_ or Joomla) that returns something, you always need to check if the returned object is what you want (for example a resource and not FALSE)

-ronin-
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Feb 26, 2008 1:39 am
Contact:

Re: i can't get my PHP/MySQL to work

Post by -ronin- » Sat Mar 15, 2008 1:03 am

could u please explain to me step by step, how to do this with MySQL?

-ronin-
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Feb 26, 2008 1:39 am
Contact:

Re: i can't get my PHP/MySQL to work

Post by -ronin- » Sat Mar 22, 2008 7:19 am

hello. it's been a week. so much has happened. so much has changed. many of u i can barely even recognize anymore, u've grown so fast. my my, how time flies. only yesterday, we were frolicking merrily in our soiled diapers under the watchful eye of that what's-his-name babysitter from the "reintegrate ex-felons back into society" program. what fun we had, living our lives carefree from titsuck to titsuck, exploring everything within reach of our vast crawl space. if only i could relive it, just for one day.

we were a curious bunch, back then. some of us have managed to maintain our youthful eagerness to soak up as much information as we can on this wonderfully mysterious world. as have i. i still find myself asking questions every now and. questions like .... "are u sure u're 18?" "...if u're here, then who the hell's in the getaway car??" "what does earwax taste like?"

today, the question on my mind is: could a suitably qualified individual please most kindly set apart a small segment of their time to peruse this thread, and quite possibly come up with some answers to help me on my way? i like joomla, and my initial impression was ..... joomla questions are best answered on the ..... get this ... official joomla forum.

thank u ever so much. :)


Post Reply