TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-17-2009, 12:46 PM   #1 (permalink)
The Contributor
 
russellharrower's Avatar
 
Join Date: Jul 2009
Posts: 80
Thanks: 13
russellharrower is on a distinguished road
Red face Need to output MYSQL as array(1 => 'January', 'feb', 'March');

Hi I need to be able to print the output of the mysql request ($quarry) into a array(1 => 'January', 'feb', 'March');

But instead of January, feb and March it needs to have the title output.

If you can help that would be great.

Thanks
Code:
$query = "SELECT id, title, content FROM push_content WHERE type = 0 ORDER by date DESC LIMIT 1";


if ($result = $mysqli->query($query)) {

    /* fetch associative array */
    while ($obj = mysqli_fetch_object($result)) {
        printf ("%s (%s)\n", $obj->title, $obj->content);
		echo"<br/>";
    }

    /* free result set */
    mysqli_free_result($result);
russellharrower is offline  
Reply With Quote
Old 07-17-2009, 02:40 PM   #2 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

why don't you use the fetch associative array static method instead of the mysqli_fetch_object?
tony is offline  
Reply With Quote
Old 07-17-2009, 02:45 PM   #3 (permalink)
The Contributor
 
russellharrower's Avatar
 
Join Date: Jul 2009
Posts: 80
Thanks: 13
russellharrower is on a distinguished road
Default

because i need the ability to call each title by them self.
if you can do an example on how i would do that using that code, that would be helpful.
russellharrower is offline  
Reply With Quote
Old 07-17-2009, 05:15 PM   #4 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

If you go object oriented style, keep it that way:

PHP Code:
$query "SELECT id, title, content FROM push_content WHERE type = 0 ORDER by date DESC LIMIT 1";


if (
$result $mysqli->query($query)) {

    
/* fetch associative array */
    
while ($obj $result->fetch_object()) {
        
printf ("%s (%s)\n"$obj->title$obj->content);
        echo
"<br/>";
    }

What exactly are you trying to do, though? You may want to give some examples, as well, so we can figure out how to help you. I, for one, did not understand how using an object instead of an array help you.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 07-18-2009, 02:50 PM   #5 (permalink)
The Contributor
 
russellharrower's Avatar
 
Join Date: Jul 2009
Posts: 80
Thanks: 13
russellharrower is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
If you go object oriented style, keep it that way:

PHP Code:
$query "SELECT id, title, content FROM push_content WHERE type = 0 ORDER by date DESC LIMIT 1";


if (
$result $mysqli->query($query)) {

    
/* fetch associative array */
    
while ($obj $result->fetch_object()) {
        
printf ("%s (%s)\n"$obj->title$obj->content);
        echo
"<br/>";
    }

What exactly are you trying to do, though? You may want to give some examples, as well, so we can figure out how to help you. I, for one, did not understand how using an object instead of an array help you.
Thanks xexon,
I want to be able to call each title like
$title1 = "this is title 1";
$title2 = "this is title2";
$title3 = "this is title3";
etc...

As I want to allow the template designer to choose how many stories to show on the front page in there design.

I also want to show the content this way.
I then want to come up with a way to have global plugins that will allow the users to choose if they want to show the posters name, date published etc...

I hope that helps.

Thanks
russellharrower is offline  
Reply With Quote
Old 07-18-2009, 04:58 PM   #6 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

Well, this would be easier.

PHP Code:
$query "SELECT id, title, content FROM push_content WHERE type = 0 ORDER by date DESC LIMIT 1"
$data = Array("title""content");
$n 0;

if (
$result $mysqli->query($query)) { 

    
/* fetch associative array */ 
    
while ($obj $result->fetch_object()) { 
        
$data['title'][$n] = $obj->title;
        
$data['content'][$n] = $obj->content;
        
$n++;
    } 

As for the option to display content I would store that into the DB and then only query for the ones that are allowed for the situation.
__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 07-18-2009, 05:02 PM   #7 (permalink)
The Contributor
 
russellharrower's Avatar
 
Join Date: Jul 2009
Posts: 80
Thanks: 13
russellharrower is on a distinguished road
Default

Quote:
Originally Posted by adamdecaf View Post
Well, this would be easier.

PHP Code:
$query "SELECT id, title, content FROM push_content WHERE type = 0 ORDER by date DESC LIMIT 1"
$data = Array("title""content");
$n 0;

if (
$result $mysqli->query($query)) { 

    
/* fetch associative array */ 
    
while ($obj $result->fetch_object()) { 
        
$data['title'][$n] = $obj->title;
        
$data['content'][$n] = $obj->content;
        
$n++;
    } 

As for the option to display content I would store that into the DB and then only query for the ones that are allowed for the situation.
Hi Just wondering what if i need to show more then 1 say like 10
russellharrower is offline  
Reply With Quote
Old 07-18-2009, 05:07 PM   #8 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

Quote:
Originally Posted by russellharrower View Post
Hi Just wondering what if i need to show more then 1 say like 10
PHP Code:
for ($n 0$n <= 9$n++) {
   echo 
"<p><strong>" $data['title'][$n] . "</strong><br />";
   echo 
$data['content'][$n] . "</p>";

Something like that...
__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 07-18-2009, 05:11 PM   #9 (permalink)
The Contributor
 
russellharrower's Avatar
 
Join Date: Jul 2009
Posts: 80
Thanks: 13
russellharrower is on a distinguished road
Default

But i need to give each one a $title->1, $title->2 etc that code will only print the data
russellharrower is offline  
Reply With Quote
Old 07-18-2009, 05:59 PM   #10 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

Quote:
Originally Posted by russellharrower View Post
But i need to give each one a $title->1, $title->2 etc that code will only print the data
Why will
PHP Code:
$data['title'][$n
not work?
__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 07-19-2009, 06:20 AM   #11 (permalink)
The Contributor
 
russellharrower's Avatar
 
Join Date: Jul 2009
Posts: 80
Thanks: 13
russellharrower is on a distinguished road
Default

have a look what that does http://www.designvisa.com/beta
russellharrower is offline  
Reply With Quote
Old 07-19-2009, 06:41 PM   #12 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

Quote:
Originally Posted by russellharrower View Post
have a look what that does http://www.designvisa.com/beta
The page is empty.
__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 07-19-2009, 08:45 PM   #13 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by russellharrower View Post
have a look what that does http://www.designvisa.com/beta
I'm not sure objects are required for that.
__________________

Village Idiot is offline  
Reply With Quote
Old 07-20-2009, 05:51 AM   #14 (permalink)
The Contributor
 
russellharrower's Avatar
 
Join Date: Jul 2009
Posts: 80
Thanks: 13
russellharrower is on a distinguished road
Default

http://www.designvisa.com/beta/index2.php sorry about that
russellharrower is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 01:44 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design