Solved

Urgent Help

Posted on 2006-11-13
17
239 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 1

Author Comment

by:getopt
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 1

Author Comment

by:getopt
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I see... how about...

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

print_r($resultArray);

?
0
 
LVL 1

Author Comment

by:getopt
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now