Solved

Urgent Help

Posted on 2006-11-13
17
273 Views
Last Modified: 2011-09-20
HI ,I retrive a list from mysql using sql Select Comand in PHP ,If I do like this :
$ThisResult = mysql_query ("select * from **** order by proID ASC ")
  or die (mysql_error());

while ($ThisRow = mysql_fetch_array ($ThisResult, MYSQL_ASSOC))

{
   $proName=$ThisRow["proName"];
   $pro=$ThisRow["pro"];

<table > something in here
.....
....
....
...
</table>

<?php
}
mysql_free_result ($ThisResult);
?>


Like this I can Retrieve all the record in dB and display in my table .BUt I don't want to do that ,I just want to retrieve a specific record I like to put in to table .So how could I do that ? help me ,thank you
 
0
Comment
Question by:getopt
  • 9
  • 8
17 Comments
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17935538
Change your query to:

SELECT *
FROM the_table
WHERE proID = 17
ORDER BY proID ASC


(Except replace the 17 with whatever record it is you want to find.)
0
 
LVL 1

Author Comment

by:getopt
ID: 17935582
I don't want use sql command ,for example ,I got 5 record in DB ,but I want to retrieve just record number 2-3-5 ,that's it ,how can I do that? .Thank you so much bro
0
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17935605
When you say "I don't want to use SQL" and then 'I want to retrieve a record from a database' you've painted yourself into a bit of a corner: SQL is the language used to retrieve information from databases.  There really isn't any other way to do it.


When you say "record number 2-3-5" does that mean your primary key is a varchar field with the value "2-3-5" or that you want records 2, 3, and 5?

If the former, the query will look like:
SELECT *
FROM the_table
WHERE whatever_the_name_of_the_field_is = '2-3-5'


If the latter, the query will look like:
SELECT *
FROM the_table
WHERE whatever_the_name_of_the_field_is IN (2, 3, 5)


0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:getopt
ID: 17935625
Ok ,I know exactly how to do with this simple SQL command like you said ,but I got a confused when I put data in table ,just like I said above ,WHen I use php retrieve record  ,that means I retrieve all the record in DB ,but I don't want to display all the record in my Website ,you know what i'm saying ,I just want to display a specific record .One again ,I just let you know don't show me do with sql command ,show me how to do in PHP .Appreciate that bro .
0
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17935657
Take exactly the code you have, only replace the query you're using now with the one you wish to use:


$ThisResult = mysql_query ('SELECT *'
. ' FROM the_table'
. "WHERE whatever_the_name_of_the_field_is = '2-3-5'")
  or die (mysql_error());

while ($ThisRow = mysql_fetch_array ($ThisResult, MYSQL_ASSOC))

{
   $proName=$ThisRow["proName"];
   $pro=$ThisRow["pro"];

<table > something in here
.....
....
....
...
</table>

<?php
}
mysql_free_result ($ThisResult);
?>
0
 
LVL 1

Author Comment

by:getopt
ID: 17935732
You still don't understand what I am saying bro ,ahahaha,but I appreciate your patient .So just think for a simple way .just imagine like this , I got 4 records in my DB xxxx ,in table yyyyy .Ok ,I use my code to retrieve data from DB ,correct ? And this is my complete codes for that :
<?php

$ThisResult = mysql_query ("select * from xxxx order by proID ASC ")
  or die (mysql_error());

while ($ThisRow = mysql_fetch_array ($ThisResult, MYSQL_ASSOC))

{
   $proName=$ThisRow["proName"];
   $proB=$ThisRow["proB"];


?>

  <table width="174" border="0">---------> this table got 1 row ,2 column ,it inside While() ,so it will create a new row for each record retrieved from DB ,correct bro ?but I don't want to do that ,I want to create new row by myself ,and put the record in that row ,by my self ,that's my question ,and I need your help bro .THank you so much
    <tr>
      <td width="94"  <?= $proName ?> </font></td>
      <td width="65"> <?= $proRate ?>  </font></td>
    </tr>
  </table>
<?php
}
mysql_free_result ($ThisResult);
?>



0
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17935748
Ok, let's back up then.  You're not talking about retrieving a row from the database at all, you're talking about... adding a row to the table in static HTML?  Adding a new record to the database based on user input?
0
 
LVL 1

Author Comment

by:getopt
ID: 17935796
I'm talking about retrieving record from DB by sql command ,and then display these records into table ,i did not talk about add a new record to DB based on user input bro :))) .And I 'm talking about retrieving  record one by one by using PHP ,I mean can I retrieve record at a specific position without using SQL command ( If using SQL i''ll do like this Select * from some_table when Some_field="Some_thing" ,that's easy bro :)) ) BUt i'm talking about PHP ,look at my code ,variables $ThisResult retrieve and hold all the record ,then I use While () to retrieve all these records that $ThisResult is holding ,correct ? Now I don't want use While ,I want to retrieve records one by one in $ThisResult .So that makes any sense to you bro ?
0
 
LVL 1

Author Comment

by:getopt
ID: 17935824
No ,bro ,one more thing I want to correct .The variable $ThisResult hold all the records ,it's impossible to call that variables ,it must be in While () ,yes ,and now I want to retrieve record from a specific row ,that make more senses bro ,correct ?
0
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17935826
mysql_fetch_array() does only retrieve records one at a time.  Try just writing:

$ThisRow = mysql_fetch_array($ThisResult);
print_r($ThisRow);

You'll see the entire contents of one row.  At that point you can do whatever you want with it.  

The way you've written it now, yes, you've also got a loop that automatically moves on to the next row, but there's certainly no rule that it has to be done that way.
0
 
LVL 1

Author Comment

by:getopt
ID: 17935837
So can I do like this ,just like $ThisRow[0] ,or $ThisRow[1] something bro ?
0
 
LVL 19

Accepted Solution

by:
VoteyDisciple earned 500 total points
ID: 17935856
I see... how about...

while ($row = mysql_fetch_assoc($ThisResults)) {
    $resultArray[] = $row;
}

print_r($resultArray);

?
0
 
LVL 1

Author Comment

by:getopt
ID: 17935874
hahahaha,that's cool bro ,ahahha,that's what I want to do ,Ok ,appreciate that bro and have a nice day bro.
0
 
LVL 1

Author Comment

by:getopt
ID: 17935947
Bro ,I got a problem with that Array ,How Can I retrieve data from that Array and put in each row in Table ? I'm stupid ,thank ou so much bro
0
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17935973
foreach($resultArray as $ThisRow) {
    // Same code as you had before
}



... though why go to the trouble of reading it into a giant array only to then just iterate through it?
0
 
LVL 1

Author Comment

by:getopt
ID: 17936125
So this is just like I did before huh bro ? So there is no way to retrieve specific record at a specific row huh ?
0
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17937374
You asked, "So can I do like this ,just like $ThisRow[0] ,or $ThisRow[1] something?"

Sure.  You can certainly do that.

If you want to "put EACH row in [the] Table" that's not the same thing.

You now have a solution either way: either access the specific row/s you want directly, or iterate through all of them.  If you're unsure how that array is structured, I suggest you use print_r() to take a look at the contents.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Force PDF to open inline as opposed to dowload 16 35
What is define("__APPROOT__", __DIR__); 6 31
curl parse data from site 20 40
How do I remove "" from json_encode 5 21
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question