Register | Login
Views: 19364387
Main | Memberlist | Active users | ACS | Commons | Calendar | Online users
Ranks | FAQ | Color Chart | Photo album | IRC Chat
11-02-05 12:59 PM
0 user currently in Programming. | 3 guests
Acmlm's Board - I2 Archive - Programming - MySQL. . . | |
Pages: 1 2Add to favorites | "RSS" Feed | Next newer thread | Next older thread
User Post
windwaker

Ball and Chain Trooper
WHY ALL THE MAYONNAISE HATE
Level: 61

Posts: 447/1797
EXP: 1860597
For next: 15999

Since: 03-15-04

Since last post: 4 days
Last activity: 6 days
Posted on 11-19-04 09:34 AM Link | Quote
Eck, I've been having a lot of problems displaying more than just the bottom row.

<?php
mysql_connect("localhost", "root", "");
mysql_select_db("news_posts");
$recnews = mysql_query("SELECT * FROM `recnews` ORDER BY `id` DESC LIMIT 5");
$ono = mysql_fetch_array($recnews, MYSQL_ASSOC);
echo "$ono[recent]";
?>

This *should* echo the last 5 rows, right? (I have id set as Primary and AUTO_INCREMENT).

It sure isn't doing what it's supposed to, I suppose .
neotransotaku

Baby Mario
戻れたら、
誰も気が付く
Level: 87

Posts: 1713/4016
EXP: 6220548
For next: 172226

Since: 03-15-04
From: Outside of Time/Space

Since last post: 11 hours
Last activity: 1 hour
Posted on 11-19-04 11:08 AM Link | Quote
why don't you try a print_r($ono) to see what is in the array?
DarkSlaya
POOOOOOOOOOOORN!
Level: 88

Posts: 2530/4249
EXP: 6409254
For next: 241410

Since: 05-16-04
From: Montreal, Quebec, Canada

Since last post: 8 hours
Last activity: 5 hours
Posted on 11-19-04 05:32 PM Link | Quote
Originally posted by windwaker

<?php
mysql_connect("localhost", "root", "");
mysql_select_db("news_posts");
$recnews = mysql_query("SELECT * FROM `recnews` ORDER BY `id` DESC LIMIT 5");
while($ono = mysql_fetch_array($recnews, MYSQL_ASSOC));
echo "$ono[recent]";
?>



What I added is in bold. By using the while() function, you will get data as long as there is something to extract.
windwaker

Ball and Chain Trooper
WHY ALL THE MAYONNAISE HATE
Level: 61

Posts: 448/1797
EXP: 1860597
For next: 15999

Since: 03-15-04

Since last post: 4 days
Last activity: 6 days
Posted on 11-19-04 08:17 PM Link | Quote
The while function didn't seem to work .

When I tried to display the raw data in the table with print_r(), it only displayed the last row of the table.
Black Lord

Level: 34

Posts: 90/453
EXP: 235639
For next: 18012

Since: 03-15-04
From: Nebraska, what's a Nebraska

Since last post: 8 days
Last activity: 1 day
Posted on 11-19-04 08:52 PM Link | Quote
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("news_posts");
$recnews = mysql_query("SELECT * FROM `recnews` ORDER BY `id` DESC LIMIT 5");
while($ono = mysql_fetch_array($recnews, MYSQL_ASSOC)){
echo "$ono[recent];
}
?>

Try that... it should work...


(edited by Black Lord on 11-19-04 11:53 AM)
neotransotaku

Baby Mario
戻れたら、
誰も気が付く
Level: 87

Posts: 1716/4016
EXP: 6220548
For next: 172226

Since: 03-15-04
From: Outside of Time/Space

Since last post: 11 hours
Last activity: 1 hour
Posted on 11-19-04 10:46 PM Link | Quote
have you tried the same command in MySQL? if the MySQL client returns the same thing, then you need to redo your query...
DarkSlaya
POOOOOOOOOOOORN!
Level: 88

Posts: 2533/4249
EXP: 6409254
For next: 241410

Since: 05-16-04
From: Montreal, Quebec, Canada

Since last post: 8 hours
Last activity: 5 hours
Posted on 11-20-04 12:34 AM Link | Quote
Originally posted by Black Lord
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("news_posts");
$recnews = mysql_query("SELECT * FROM `recnews` ORDER BY `id` DESC LIMIT 5");
while($ono = mysql_fetch_array($recnews, MYSQL_ASSOC)){
echo "$ono[recent];
}
?>

Try that... it should work...


Looks like I forgot my braces. Anyway, this seems like the good answer to me but only windwaker can tell.
windwaker

Ball and Chain Trooper
WHY ALL THE MAYONNAISE HATE
Level: 61

Posts: 449/1797
EXP: 1860597
For next: 15999

Since: 03-15-04

Since last post: 4 days
Last activity: 6 days
Posted on 11-20-04 07:12 AM Link | Quote
OMG guess what.

It worked!

I have another question...

How do I delete certain rows in a table? And how do I display certain rows, like say, rows with id 50-100?
neotransotaku

Baby Mario
戻れたら、
誰も気が付く
Level: 87

Posts: 1720/4016
EXP: 6220548
For next: 172226

Since: 03-15-04
From: Outside of Time/Space

Since last post: 11 hours
Last activity: 1 hour
Posted on 11-20-04 07:18 AM Link | Quote
delete from [table] where [qualifying statement]

select * from [table] where id>=50 and id <=100
windwaker

Ball and Chain Trooper
WHY ALL THE MAYONNAISE HATE
Level: 61

Posts: 450/1797
EXP: 1860597
For next: 15999

Since: 03-15-04

Since last post: 4 days
Last activity: 6 days
Posted on 11-20-04 07:50 AM Link | Quote
This
Rocks

Thanks so much, neotransotaku! This is awesome!

One more question...

I'm adding something in a file that adds to the PMA DB...

What I'm adding looks like this:

$date = date("m / d / y");
mysql_query("INSERT INTO `recnews` (`recent`, `date`) values ('<div class=newhead><a href=$link>$head</a></div><br><br>$summary<br><a href=$link>Read more</a> -- ', '$date')");


Although I want the contents of $summary to be stripslashed. How would I do this? o.o

Edit: that was a horrible question that didn't need to be answered XD.


(edited by windwaker on 11-19-04 11:23 PM)
SyntaxLegend

Double metal axe
Level: 25

Posts: 103/222
EXP: 78264
For next: 11356

Since: 04-21-04
From: Australia

Since last post: 20 days
Last activity: 10 hours
Posted on 11-20-04 10:32 AM Link | Quote
$summary=stripslashes($summary);
$date = date("m / d / y");
mysql_query("INSERT INTO `recnews` (`recent`, `date`) values ('< div class=newhead>< a href=$link>$head< /a>< /div>

$summary
< a href=$link>Read more< /a> -- ', '$date')");

that may work, not sure, else try:

$summarya=stripslashes($summary);
$date = date("m / d / y");
mysql_query("INSERT INTO `recnews` (`recent`, `date`) values ('< div class=newhead>< a href=$link>$head< /a>< /div>$summarya
< a href=$link>Read more< /a> -- ', '$date')");

And If that doesnt work:
$date = date("m / d / y");
mysql_query("INSERT INTO `recnews` (`recent`, `date`) values ('".stripslashes(< div class=newhead>< a href=$link>$head< /a>< /div>$summarya
< a href=$link>Read more< /a> -- )."', '$date')");


(edited by SyntaxLegend on 11-20-04 01:34 AM)
(edited by SyntaxLegend on 11-20-04 01:40 AM)
Xkeeper
The required libraries have not been defined.
Level: NAN

Posts: -3066/-863
EXP: NAN
For next: 0

Since: 03-15-04

Since last post: 2 hours
Last activity: -753366 sec.
Posted on 11-20-04 11:36 AM Link | Quote
Originally posted by windwaker
Edit: that was a horrible question that didn't need to be answered XD.
...

Yeah, I think he figured it out; all you'd have to do is stick it into a var, stripslash the var, then put the var in.

Rydain

Ropa
Blaze Phoenix
Runs With the Dragon Within

Level: 42

Posts: 311/738
EXP: 490056
For next: 31306

Since: 03-15-04
From: State College, PA

Since last post: 6 days
Last activity: 8 hours
Posted on 11-20-04 02:03 PM Link | Quote
select * from [table] where id>=50 and id <=100

Or you could

select * from [table] where id between 50 and 100;

SQL has a bunch of other similarly nifty conditionals that are very good to know. in is another good one because it lets you specify a list of values to look for instead of making a ginormous pile of or's. For instance:

select * from [table] where id in (1, 6, 21, 40);

(Conversely, use "not in" to exclude the listed ID's.)
SyntaxLegend

Double metal axe
Level: 25

Posts: 104/222
EXP: 78264
For next: 11356

Since: 04-21-04
From: Australia

Since last post: 20 days
Last activity: 10 hours
Posted on 11-20-04 03:10 PM Link | Quote
Originally posted by Rydain
select * from [table] where id between 50 and 100;
select * from [table] where id in (1, 6, 21, 40);
Just clarifying. Would the correct code be set out as:
SELECT * FROM [table] WHERE id BETWEEN 50 AND 100;
and
SELECT * FROM [table] WHERE id NOT IT (1, 6, 21, 40);
neotransotaku

Baby Mario
戻れたら、
誰も気が付く
Level: 87

Posts: 1723/4016
EXP: 6220548
For next: 172226

Since: 03-15-04
From: Outside of Time/Space

Since last post: 11 hours
Last activity: 1 hour
Posted on 11-20-04 10:39 PM Link | Quote
actually, case doesn't matter when it comes to MySQL keywords... case only matters when it comes to your column names and data.
windwaker

Ball and Chain Trooper
WHY ALL THE MAYONNAISE HATE
Level: 61

Posts: 452/1797
EXP: 1860597
For next: 15999

Since: 03-15-04

Since last post: 4 days
Last activity: 6 days
Posted on 11-21-04 02:59 AM Link | Quote
Whoa, I tested those, they all worked.

Thanks guys .

Another question...

how do I add to just specific rows? Like if I wanted to add "zomglol" to row 45, how would I do that?


(edited by windwaker on 11-20-04 08:01 PM)
neotransotaku

Baby Mario
戻れたら、
誰も気が付く
Level: 87

Posts: 1727/4016
EXP: 6220548
For next: 172226

Since: 03-15-04
From: Outside of Time/Space

Since last post: 11 hours
Last activity: 1 hour
Posted on 11-21-04 07:09 AM Link | Quote
manually write in the id value.

insert into [table] (id, col1, col2) values (45, "zomglol", "boo");
windwaker

Ball and Chain Trooper
WHY ALL THE MAYONNAISE HATE
Level: 61

Posts: 453/1797
EXP: 1860597
For next: 15999

Since: 03-15-04

Since last post: 4 days
Last activity: 6 days
Posted on 11-21-04 09:29 AM Link | Quote
ooo, really sweet.

now; how would I add to the beginning of a certain row?


(edited by windwaker on 11-21-04 01:10 AM)
(edited by windwaker on 11-21-04 01:14 AM)
SyntaxLegend

Double metal axe
Level: 25

Posts: 105/222
EXP: 78264
For next: 11356

Since: 04-21-04
From: Australia

Since last post: 20 days
Last activity: 10 hours
Posted on 11-21-04 03:09 PM Link | Quote
what do you mean, write to the bigening of a row.

you could update the row

UPDATE table SET id=1, col1='Hi', col2='there!' WHERE id=1;

or somethig else?
neotransotaku

Baby Mario
戻れたら、
誰も気が付く
Level: 87

Posts: 1737/4016
EXP: 6220548
For next: 172226

Since: 03-15-04
From: Outside of Time/Space

Since last post: 11 hours
Last activity: 1 hour
Posted on 11-21-04 10:01 PM Link | Quote
I've also noticed that a lot of your question could be answered if you also tried looking a little bit at the reference manual: http://dev.mysql.com/doc/
Pages: 1 2Add to favorites | "RSS" Feed | Next newer thread | Next older thread
Acmlm's Board - I2 Archive - Programming - MySQL. . . | |


ABII


AcmlmBoard vl.ol (11-01-05)
© 2000-2005 Acmlm, Emuz, et al



Page rendered in 0.013 seconds.