farsiscript
Aug 24 2006, 03:20 PM
hi all i know php and my sql i want to know how can show mysql result in this tabel for example : CODE <table cellpadding="0" cellspacing="0" width="200" height="151"> <!-- MSTableType="layout" --> <tr> <td height="21" width="100" valign="top">1</td> <td height="21" width="100" valign="top">8</td> </tr> <tr> <td height="21" width="100" valign="top">2</td> <td height="21" width="100" valign="top">9</td> </tr> <tr> <td height="21" width="100" valign="top">3</td> <td height="21" width="100" valign="top">10</td> </tr> <tr> <td height="22" width="100" valign="top">4</td> <td height="22" width="100" valign="top">11</td> </tr> <tr> <td height="22" width="100" valign="top">5</td> <td height="22" width="100" valign="top">12</td> </tr> <tr> <td height="22" width="100" valign="top">6</td> <td height="22" width="100" valign="top">13</td> </tr> <tr> <td height="22" width="100" valign="top">7</td> <td height="22" width="100" valign="top">14</td> </tr> </table>
this table show result in 2 columns . Is it imposible to show result in this tabale with 1 query ? Just paste query here thanks all
Reply
truefusion
Aug 24 2006, 03:56 PM
It might be more possible, if you changed the order that it is sorted in. For example, instead of it counting going down a column like in your example. It would count going from left to right. And you would keep track of it. Whenever it retrieves two results, you tell the script to add a new row, and then reset the "tracker". And have it loop until no more results are found. But since i have not fully thought through this, a problem would result if the tracker doesn't reach the limit. Cause then it won't end the row. Anyways, i hope i gave you a general idea on how to go about it.
Reply
shadowx
Aug 24 2006, 04:17 PM
Yes it is possible i think. I did find a decent tutorial on this but i cant find it any more. Basically you get the data from the sql query into an array. I assume you know how to do this, if not see the link at the end. Basically you create the array from the output of the query then use a loop to execurte code like: CODE echo "<tr><td>$array[result];</td><td>$array[result];</td>"; obviously thats not suitable code to use but it shows the idea. A better tutorial can be found here http://www.desilva.biz/arrays/poparray.htmlAnd also all over the web using google to search for something like "php mysql array" or search the function "mysql_fetch_array()" i belive thats correct, its been a while scince i did any database work.
Reply
farsiscript
Aug 24 2006, 07:28 PM
Hi thanks dears shadowx and truefusion but i cannot understand i read http://www.desilva.biz/arrays/poparray.html if you can plz make me a sample thanks more and more
Reply
shadowx
Aug 24 2006, 08:49 PM
Humm if i remember back to when i learnt it the code was something like this. Lets pretend that the table users contains two fields, username and password and one user is called joe. CODE
$sql = "SELECT * FROM users WHERE username=joe";
$result = $msql_query($sql, $link);
$row = mysql_fetch_array($result);
// now we have the data in our array called $row so we can use echo ""'; to pull it out and print it.
echo "<TR><TD>$row['username']</TD><TD>$row[password]</TD>";
I appologise i misunderstood before and the link i gave you wasnt very usefull although its jogged my memory so if for example you wanted to pull out several rows of data from your table such as every user living in england something like this should work assuming the table has three fields, country, username and password. CODE
$sql = "SELECT * FROM users WHERE country=england";
$result = $msql_query($sql, $link);
while ($row = mysql_fetch__array($result) {
//get data into array then use it untill there are no more rows to retrieve.
echo "<TR><TD>$row['username']</TD><TD>$row[password]</TD></TR>";
}
Thats probably not entirely correct as im not an expert and its been a while but it gives a good idea of what is needed and should be fairly accurate. Basically you get the data from the table using the query. You then set up a loop that says "while there are still rows for me to get im going to get them then create a HTML table with these results. When theres none left ill stop." So if there were three records in the database who live in england you should get three table rows in the HTML output each with a different users details. Thats the plan atleast! Like i said try looking up the mysql_fetch_array() function and it should help. This is the site where i learnt this from and i belive it should be exactly what youre after. http://www.tizag.com/mysqlTutorial/mysqlselect.php
Reply
electron
Aug 25 2006, 03:31 AM
This is good if you have a small page. Well you would get a error if there were no results from the query due to either a wrong query or No results in the table. Therefore your mysql_fetch_array() would give you an error. Hence you must check the $reults first or the mysql_num_rows() to see if there are any results. Check it as follows: CODE if(!$result || mysql_num_rows($result) < 1){
//Give the error (God knows what you want) return;
} Also i prefer to use the for loop instead of while. So do what pleases you. One last comment is that you should always keep the processing file and the theme file seperate. It makes it easier to understand and creates an insulation between the two.
Reply
farsiscript
Aug 25 2006, 10:10 AM
oh thanks dear electron its nice help i have one question can i show one row details in 2 td ? for example i change it : CODE $sql = "SELECT * FROM users WHERE username=joe";
$result = $msql_query($sql, $link);
$row = mysql_fetch_array($result);
// now we have the data in our array called $row so we can use echo ""'; to pull it out and print it.
echo "<TR><TD>$row['username']</TD><TD>$row['username']</TD>"; ? can i show in 2 td username field ? thanks more and more for more its my sql file and mysql database code : CODE CREATE TABLE host ( id tinyint(4) NOT NULL auto_increment, name text NOT NULL, PRIMARY KEY (id) ) TYPE=MyISAM; its my show.php code : CODE <?php include "config.php";
echo "<table cellpadding='0' cellspacing='0' width='154'> <!-- MSTableType='layout' -->";
$sql = "select * FROM host order by id";
$result = $msql_query($sql, $link);
while($row = mysql_fetch_array($result)); {
echo "<tr><td height='29' width='74'>$row['name']</td><td height='29' width='80'>$row['name']</td></tr>"; }
echo "</table>"; ?>
I want show next name at table for example in td1 show name one and in td show name 2 in database and goes to end for example if in my database i have 2 name farsi and script i want show in tabale in this format <tr><td height='29' width='74'> farsi</td><td height='29' width='80'> script</td></tr> and <tr><td height='29' width='74'> 3 name</td><td height='29' width='80'> 4name</td></tr> <tr><td height='29' width='74'> 5 name</td><td height='29' width='80'> to end of tabel</td></tr> dear if you can edit my show.php code , plz help me thanks and more thanks
Reply
shadowx
Aug 27 2006, 06:25 PM
I think the only way to get it to show two usernames in one table is to change the php like this: CODE echo "<TR><TD>$row['username']</TD>";
Then loop that line somehow. Otherwise you will get the same username twice.
Reply
farsiscript
Aug 27 2006, 06:53 PM
wooow i make it its my query and tabale : CODE $getpet = "1"; $level1 = "1"; $level2 = "2"; $level3 = "3"; $level4 = "4"; $level5 = "5"; $max_results = 20;
$sql = mysql_query("SELECT * FROM host ORDER BY rate DESC LIMIT $from, $max_results"); while($row = mysql_fetch_array($sql)) { $name = $row['name']; $rate = $row['rate']; if ($getpet == "$level1"){ echo "<tr><td height='19' width='96'><font face='Tahoma' style='font-size: 8pt'><font color='#800000'>$num . </font><a title='$rate' href='send.php?nam=$name'><font color='#808000'> <span style='text-decoration: none'>$name</span></font></a></font></td>"; $getpet = "2"; $num = ($num + 1); }elseif ($getpet == "$level2"){ echo "<td height='19' width='97'><font face='Tahoma' style='font-size: 8pt'><font color='#800000'>$num . </font><a title='$rate' href='send.php?nam=$name'><font color='#808000'> <span style='text-decoration: none'>$name</span></font></a></font></td>"; $getpet = "3"; $num = ($num + 1); }elseif ($getpet == "$level3"){ echo "<td height='19' width='97'><font face='Tahoma' style='font-size: 8pt'><font color='#800000'>$num . </font><a title='$rate' href='send.php?nam=$name'><font color='#808000'> <span style='text-decoration: none'>$name</span></font></a></font></td>"; $getpet = "4"; $num = ($num + 1); }elseif ($getpet == "$level4"){ echo "<td height='19' width='97'><font face='Tahoma' style='font-size: 8pt'><font color='#800000'>$num . </font><a title='$rate' href='send.php?nam=$name'><font color='#808000'> <span style='text-decoration: none'>$name</span></font></a></font></td>"; $getpet = "5"; $num = ($num + 1); }elseif ($getpet == "$level5"){ echo "<td height='19' width='97'><font face='Tahoma' style='font-size: 8pt'><font color='#800000'>$num . </font><a title='$rate' href='send.php?nam=$name'><font color='#808000'> <span style='text-decoration: none'>$name</span></font></a></font></td></tr>"; $getpet = "1"; $num = ($num + 1); }
Reply
Recent Queries:--
mysql results into html table - 0.81 hr back. (1)
-
retrieve scores mysql - 15.55 hr back. (1)
-
"mysql""display table""array" - 29.32 hr back. (1)
-
display mysql data in a table - 31.47 hr back. (1)
-
how to display top 5 rows in mysql - 34.14 hr back. (1)
-
display mysql results javascript - 34.62 hr back. (1)
-
mysql results in table - 44.38 hr back. (1)
-
mysql update display result - 51.75 hr back. (1)
-
display mysql results in two columns - 52.39 hr back. (1)
-
mysql table results - 54.71 hr back. (1)
-
display result from mysql in table - 54.75 hr back. (1)
-
display various table results in php - 54.92 hr back. (1)
-
mysql result in two rows of table - 58.80 hr back. (1)
-
show mysql results - 65.29 hr back. (1)
Similar Topics
Keywords : display, mysql, results, table
- Create Table - Mysql Code - Help
(1)
Mysql Error
(3) ok i need some more help from the wonderful coders here at Trap. I'm almost done with my CMS
script, but i'm having a problem with the installer.php file, when it trys to inseret the user
data into the database i keep getting the following error: CODE mySQL Error: You have an
error in your SQL syntax; check the manual that corresponds to your MySQL server version for the
right syntax to use near ';INSERT INTO `members` (`id`, `name`,
`username`, `password`, `email`, `title`) ' at lin....
Html Form!
Using MySQL?! (4) Hey, I need your help again! I need some good working tutorial how I can update my SQL through
HTML form. I did use some tutorials online found with the help of google; but they do not work
properly; I mean there are still small mistakes. I need to have a good tutorial to follow. It
should be based on security and more things. It has to be done in proper way.......
Best Php And Mysql Editor For Noobs
anyone any php or mysql editor that is good for noob (6) hi there guys, from my previous posting, i am a noob in php and mysql programming. I want to know
if there are any php and mysql editors which are best for me as a noob. i appreciate your kindness
....
Php And Mysql Programming
anyone knows a code for mysql and php (2) hi everyone! I am making a program using php and mysql...I am a noob on this so i need your
help guys...I want to make a simple program that will some values and then store them on a database
and then retrieve them...uhmm let me give an example out put of what i need. This is the example
say..: Enter First Name: Enter Last Name:
Enter Age: Enter Address: ..those
are the data needed for input values...my question now is how can I make a database....
Best Sites For Learning Php-mysql
(4) Hi I was reminded of this earlier by a post in a topic, meant to post it but forgot and the topic on
php books reminded me. Well anyway there is tyhschools for learning php (unless someone else knows
a better 1) but I wan't to know what is the best site for using php with mysql (using
phpmyadmin) also whats the difference between postgresql and mysql? though I must admit the
postgresql version of phpmyadmin whatever it's called looks better (visually)!....
Tools Needed!
PHP & MySQL (9) Hello, everyone! I need some tools for those two things to test PHP scripts coming together with
database on my laptop, instead checking them on a web-server which takes time.....
How To Display Images Of A Directory
(4) I am trying to do a simple thing. I want to display all the images of a directory on a single page
with the checkbox next to each image, so that i can select multi images and i can delete selected
images. Following few lines of code display the images of a directory.. i need help to put the
check boxes with each image. and I dont understand how can i select multi images with check box and
then delete them. I hope someone can help. thanks. CODE <?php $path = "./";
$dir_handle = @opendir($path) or die("Unable to open folde....
Php + Mysql Question!
While inserting data into MySQL, how can I know if the data I'm in (4) Basically, I want to know if the Data I'm inserting through a Form is already there or not. Sort
of a Username registration page. I have this, but it doesn't appear to work... CODE
$result = mysql_query("SELECT * FROM users WHERE
username='$username'"); if($result == 1) { echo
'<h1>ERROR!</h1>The username you have chosen already exists!'; }
....
Mysql Won't Update
(4) Ok, so I'm making some arcade administration software so I don't have to add games the hard
way, well anyway, one of the features I have is that on the homepage is a featured author and as
such I just have it so it updates one line in the mySQL. Well, the page with the form passes on the
varibles fine and the updating page recieves them because I echoed everything, then I build the
query and I even echo the query and it comes out exactly how I want it to, but for some reason, the
database itself won't update even though all the varibles are there. Here's....
[php/mysql]id Trouble [resolved]
(3) session_start(); include "database.php"; if (!$_SESSION || $_SESSION { // User
not logged in, redirect to login page Header("Location: main.php"); } $result =
mysql_query("select * from users order by id asc"); while($r=mysql_fetch_array($result))
{ $username=$r ; $info=$r ; $msn=$r ; $email=$r ;
$id=$r ; $password=$r ; $userlevel=$r ; echo "
user ID User Level U....
[mysql/php]need Som Basic Help
(13) QUOTE session_start(); include "database.php"; include "edit.inc.php"; if (!$_SESSION
) { // User not logged in, redirect to login page Header("Location: main.php"); }
if(isset($_POST )){ $email = $_POST ; $msn = $_POST ; $info =
$_POST ; $updateemail = "UPDATE users SET email = '$email', msn =
'$msn', info = '$info' WHERE username = '$username'";
mysql_query($updateemail) or die("culd not edit your info"); echo "info updated"; } //
Display log....
[mysql]get Id Of Loged In User?
(7) how to get the id number of the loged in user? my db is id. username. password. i have tryed a
few things.. but i never seem to get it right /ohmy.gif" style="vertical-align:middle" emoid=":o"
border="0" alt="ohmy.gif" />....
The Artists Tutorials :mysql Basic Commands
The Artists is an online programming unit and gfx designing clan. (0) Let's Talk about basic mysql commands used in php. I will now show you a list of the most common
MySQL FUNCTIONS : QUOTE mysql_connect(MySQL server name,username,password) - opens a connection
to a MySQL server. mysql_select_db(database name,connection id) - selects a database residing on
the MySQL server. The database name parameter referes to an active database on the MySQL server that
was opened with the mysql_connect function. The connection identifier is a reference to the current
MySQL connection. mysql_query(sql query) - sends a query to the currently ac....
To Search Within Search Results
To search within search results (0) Is there a good and efficient way of searching within previously searched records using PHP/MySql? I
tried searching on google with several keywords like nested search, search within results, recursive
search with PHP and MySql, haven't got a clue so far yet. But I thought it might be just storing
previously queried sql statements and to a select on it each time the search button is called? Any
ideas?....
Problem With A Mysql Join
Problem with a mysql join (2) Hello I am trying to write a script whereby I can pull an image out of one database table and
display it in relation to its category_id in another table. I am using a my_sql join function that
is joining the tables correctly, however it only shows the one same image from the top field of
those combined rows on every single page. I need it display the image according to its category_id
for that particular page. I am thinking I need to set variables to represent those specific rows but
I'm not sure how to do that. Here is my code CODE { $result = mysql_que....
Getting Php 5 To Work With Mysql
getting PHP 5 to work with MySQL (0) Just thought this would be of extreme help to those who are planning to migrate to php5 and still
continue using MySQL same way as before:.... to get mysql work with the php 5 copy
/dll/libmySQL.dll to the directory where php 5 resides and copy the /extensions/php_mysql.dll to the
directory where php.exe resides.(if you can't find the two above files probably you are using an
old release of php 5.you should check for latest at :http://snaps.php.net/) in additon uncomment
extension line in php.ini and add the following code to a gnereal database file(dbcon.php) in m....
How To Display The Latest Forum Post On Main Page
(4) Hey does anyone know how to display the latest forum post on the main page of a website? I'm new
to PHP and have no idea what to do. Thanks in advance!....
Php And Mysql Applications
(3) Ok I have started useing PHP and MySQL recently and I am wondering how I go about createing an
application. I looked for tutorials and guids at w3schools.com but couldnt find what i was looking
for. All I really need is a list of a few steps to take to get a general idea on were to start when
makeing an application. I would appreciate any help you may have to offer.....
<?php ?> Get Search Results To Your Localhost
Simple way to get 100 results without allowing cookies (2) Ultimately simple script that allows you getting google search results to your localhost. This is
the first part of the Crawler script i'm developing, and if you are interested in developing the
script with me, IM me @icq328866661@msn/evil_matak/ a \hotmail-com. Here's the form
part... QUOTE search.php QUOTE if (@$_POST ==""){ echo "What are you
doing?"; } else{ $query =
file_get_contents("http://www.google.com/search?q=".urlencode($_POST
)."&num=100&hl=en&ie=UTF-8&filter=2"); //needs to be added with more queries ....
Php, Mysql, Apache
(4) ok, i am hosting a smf (simple machines forum) and in order to do so, i need apache, mysql and php
installed. so i got apachefriends xampp. it works, but idk where to go from there. am i ready to
just host and stuff. or do i need to do a couple more things. basically what i need is a guide on
how to set up a php website. or just confirmation that all i have to do is load the files onto the
website, then im ready to go. thank you....
Some Mysql Basics
(4) Greetings this tutorial will show you some mysql basics.. MySQL is one of the most used database. a
simple config file at the top add this CODE <?php ?> after <?php add
$username= "root"; // Username that has access to your database $password=
""; //Password that has access to your database $host = "localhost"; // The
host where the database is (mostly this is localhost) $db = "databasename"; //
The name of the database where you want to work with //connect to the database mysql_connect(....
Help With Moving Html Form Results To Shopping Cart?
(3) Hello All- So I think I'm tackling a pretty big project here and was looking for some help... I
am fairly new to extensive coding (beyond HTML and a little bit of JavaScript) and wanted to know
how I can recall HTML form results on the next page (in a shopping cart) with a price based on the
choices picked in the form. It sounds complicated...look at this example: Check out this page:
http://www.plugcomputers.com/intelprobuild.php See how when the user goes through and picks all
their computer parts a price at the bottom shows the system price based on their sel....
Simple Mysql Query Limiting
(9) Simple MySQL Query Limiting CODE <?php // If mypage?limit=blah is not defined returs 5
if ( $_GET['limit'] == NULL ) { $limit = 5; } // Else else {
$limit = $_GET['limit']; } $query = mysql_query("SELECT
* FROM members LIMIT '$limit'") or die(mysql_error()); while
($sql = mysql_fetch_array ($query) ) { echo
$sql['mem_name'] . '<br>'; } ?> Have fun......
Display The Current Date/time
With a simple PHP code (3) Use this code to display the current date and time. CODE <?php $date =
date('l dS \of F Y h:i:s A'); echo "$date"; ?>
"l" would display the current day of the week such as Sunday. d displays the day of the month...
such as 1 and S adds the appropriate suffix(st). /of simply displays the word "of". F displays the
current month with no abbreviations while Y displays the four digit year(2007). "h" displays the
current hour with leading zeros if necessary(Ex. 06 for 6 o'clock). "i" displays the m....
Php Search Engine Script For Mysql Database
(11) A search engine is provided to facilitate the user with undemanding and clear-cut search options.
The search facility includes simple search, search by title, search by word/phrase, ect… Thus, the
user is at a safe distance from the risk of selecting files/folders ambiguously. In addition, a
history of recent searches can be preserved for future perusal. Now
day’s visitors have a large option for his needs on internet and so visitors are not vesting their
time by following the dead links on your site. So a search engine is essential for your....
Creating Profiles In Php/mysql ?
(7) i've started to learn php..im familiar to basics of php and mysql now.Now for example i want
that some user can register to my website , and after that he can Login and log out , and he can see
his profile.is there any tutorial about this ? or any helping url .. or any helping answer please
/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />....
Can You Add Images Into A Mysql Database?
Using Php? (20) I'm learning php in class right now, but I'm still not that good at it, what I'm
wondering is when I write the php so that it can connect with a database, can I at the same time
have it that it is able to display back images that I choose. Like, I want a search feature, where
you can search for a keyword, and it will bring back a list of all the possible entries with that
keyword, but each of these entries will have a photo associated with it. Now, do I put these image
files directly into the database, or do I write the code to link them from my files to th....
Increment A Mysql Column
how to increment a MySQL column one unit (6) Hi, I have a column in a MySQL table which contains a counter of the views of the object described
by this table. I would like to increment this value by one everytime the object is viewed. Obviously
came into my mind the possibility of retrieving the value of this field, store it in a variable
increment this value by one and perform an UPDATE query again with this new value. My question is if
there is a MySQL option to update the field with its actual value plus an unit increment. I hope you
understand the issue.....
Problem On Mysql "order By"
(5) Can someone please help...? I have a problem with using "ORDER BY" in mysql... CODE SELECT *
FROM `foo` WHERE b='abc' ORDER BY 'number' ASC i want to sort the table out by
the value in "number" which is a number.. but it came out to be sort by like this way...
1->10->2->20 it only sort out the front digit.... but what i want is it will sort by how great the
number is like this... 1->2->3........->10....->20 sorry my english isn't good enough...to
describe my problem properly... hope you can understand and help me on this.....thx....
Looking for display, mysql, results, table
|
|
Searching Video's for display, mysql, results, table
|
advertisement
|
|