 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
07-17-2009, 12:46 PM
|
#1 (permalink)
|
|
The Contributor
Join Date: Jul 2009
Posts: 80
Thanks: 13
|
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);
|
|
|
|
07-17-2009, 02:40 PM
|
#2 (permalink)
|
|
The Addict
Join Date: Aug 2008
Posts: 336
Thanks: 8
|
why don't you use the fetch associative array static method instead of the mysqli_fetch_object?
|
|
|
|
07-17-2009, 02:45 PM
|
#3 (permalink)
|
|
The Contributor
Join Date: Jul 2009
Posts: 80
Thanks: 13
|
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.
|
|
|
|
07-17-2009, 05:15 PM
|
#4 (permalink)
|
|
The Frequenter
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
|
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.
|
|
|
|
07-18-2009, 02:50 PM
|
#5 (permalink)
|
|
The Contributor
Join Date: Jul 2009
Posts: 80
Thanks: 13
|
Quote:
Originally Posted by xenon
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
|
|
|
|
07-18-2009, 04:58 PM
|
#6 (permalink)
|
|
The Addict
Join Date: May 2009
Posts: 287
Thanks: 5
|
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.
|
|
|
|
07-18-2009, 05:02 PM
|
#7 (permalink)
|
|
The Contributor
Join Date: Jul 2009
Posts: 80
Thanks: 13
|
Quote:
Originally Posted by adamdecaf
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
|
|
|
|
07-18-2009, 05:07 PM
|
#8 (permalink)
|
|
The Addict
Join Date: May 2009
Posts: 287
Thanks: 5
|
Quote:
Originally Posted by russellharrower
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...
|
|
|
|
07-18-2009, 05:11 PM
|
#9 (permalink)
|
|
The Contributor
Join Date: Jul 2009
Posts: 80
Thanks: 13
|
But i need to give each one a $title->1, $title->2 etc that code will only print the data
|
|
|
|
07-18-2009, 05:59 PM
|
#10 (permalink)
|
|
The Addict
Join Date: May 2009
Posts: 287
Thanks: 5
|
Quote:
Originally Posted by russellharrower
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?
|
|
|
|
07-19-2009, 06:20 AM
|
#11 (permalink)
|
|
The Contributor
Join Date: Jul 2009
Posts: 80
Thanks: 13
|
|
|
|
|
07-19-2009, 06:41 PM
|
#12 (permalink)
|
|
The Addict
Join Date: May 2009
Posts: 287
Thanks: 5
|
Quote:
Originally Posted by russellharrower
|
The page is empty.
|
|
|
|
07-19-2009, 08:45 PM
|
#13 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
Quote:
Originally Posted by russellharrower
|
I'm not sure objects are required for that.
|
|
|
|
07-20-2009, 05:51 AM
|
#14 (permalink)
|
|
The Contributor
Join Date: Jul 2009
Posts: 80
Thanks: 13
|
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|