Need Some Basic Mysql Coding Help

Started on the old forum in July 2008 · view the original in the archive · old links redirect here

7 replies · 665 views · started 18 years ago · 1 min read

2 participants
Guest #1

ive got a table with

id|username|password|gender|month|

i want to echo the usernames who have their "month" as "june" and only the first 20 results should be echoed and please if possible use "for" loop instead of "while"

i got this below code from ansh which is similar to my table

$get_data_query = @mysql_query("SELECT `id`, `username`,`password`,'gender','month' FROM `mytable` ORDER BY id ASC limit 20;");
while ($get_data_query_result=mysql_fetch_array($get_data_query)){
++$i; print "[b]$i.[/b]Name: $get_data_query_result[1]
 month: $get_data_query_result[4]}
Guest #3

i got it thnks any way

<?php
// Make a MySQL Connection
$result = mysql_query("SELECT * FROM mytable   WHERE month= 'june' ORDER BY id ASC limit 5;") or die(mysql_error());
     

$i=6;

while($row = mysql_fetch_array($result)){
$i++;
    echo $row[1]. " - ". $row[3];
    echo "
";

}
?>

i got 5 results in one page does any one know how to do pagination with this

wizard Senior · 493 posts #5
$info = mysql_query("SELECT id, name, password, gender, month FROM mytable WHERE month='june' ORDER BY id ASC LIMIT 20,0");

while($do = mysql_fetch_array($info))
{
    echo 'ID: '.$do[0];
    echo '
Name: '.$do[1];
    echo '
Password: '.$do[2];
    echo '
Gender: '.$do[3];
    echo '
Month: '.$do[4];
}
learner Lead · 587 posts #7

i tried

$onl = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_online"));
echo "<a href=\"index.php?action=gonline&sid=$sid\">Online! $onl[0]</a>
";

and get error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/public_html/index.php on line 950

Failure is not when a girls leaves you, its only when you let her go virgin. heheh!!

BEST MOBILE ADVERTISER

External image (may be gone)

Guest #8

did you supply the column name all i see is the table name

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close