Would you please help me in how to get the remaining column values so that I will be able to echo each value in my pages. Right now, my function is set to return just to return one field's value (line 13) but I want to do the same for all the remaining fields. How do I write loopings like foreach .... -
class Setting extends Domain
-
{
-
function __construct()
-
{
-
parent::__construct( 'Settings', array 'Settings_id', 'webSite', 'Slogan', 'Title'));
-
}
-
function Sett()
-
{
-
global $db;
-
$SS = $db->query('SELECT * FROM Settings where webSite = "'.$this->domain().'"');
-
while ($SS->fetchInto($row, DB_FETCHMODE_ASSOC)) {
-
return $row[webSite];
-
}
-
}
-
}
-
-
$Set = new Setting();
-
echo $Set->Sett($row[webSite]);
-
3 3803 Atli 5,058
Recognized Expert Expert
Hi.
Please post your code inside [code] tags! It is almost impossible to read without them.
Also, please give your threads descriptive titles. They help our other members finding threads they are likely to be able to help with, thus increasing your chances of getting an answer.
All this, and more, can be read in the Posting guidelines, which all members are required to follow.
Thank you :)
As to your question.
Not knowing exactly which database system you are using, or even how your class handles the database results, I will assume you are using MySQL.
Try something like: -
$result = mysql_query("SELECT * FROM tbl");
-
while($row = mysql_fetch_assoc($result)) {
-
$data[] = $row
-
}
-
return $data;
-
Hi, thank you for the help very much. When I tried that, I get array output. When I tried this:
[PHP] $data[] = $row;[/PHP]
[PHP] foreach ($row as $data) {return $data;}[/PHP]
I get the value of the first field. So how do I print the values for the remaining fields from this code. Any idea?
Hi.
Please post your code inside [code] tags! It is almost impossible to read without them.
Also, please give your threads descriptive titles. They help our other members finding threads they are likely to be able to help with, thus increasing your chances of getting an answer.
All this, and more, can be read in the Posting guidelines, which all members are required to follow.
Thank you :)
As to your question.
Not knowing exactly which database system you are using, or even how your class handles the database results, I will assume you are using MySQL.
Try something like: -
$result = mysql_query("SELECT * FROM tbl");
-
while($row = mysql_fetch_assoc($result)) {
-
$data[] = $row
-
return $data;
-
}
-
Atli 5,058
Recognized Expert Expert
I'm afraid I made a small error in my previous post. I put the return keyword inside the while loop, which will of course only return the first row of data. I've fixed my previous post.
As to your problem, I think you may be misunderstanding how the return keyword works.
Once you call the return keyword, the function is immediately terminated, returning the value you specify.
So, calling return inside any loop will always terminate the loop and it's parent function on it's first run. In your case, this will always leave you with a single field or row, depending on your code.
Consider this code. It will simply print all fields of all rows: -
$result = mysql_query("SELECT * FROM tbl");
-
$rowIndex = 0;
-
while($row = mysql_fetch_assoc($result)) {
-
echo "Row {$rowIndex}: <br />";
-
foreach($row as $_key => $_value) {
-
echo " - {$_key} = {$_value}";
-
}
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Josep |
last post by:
Hi,
I'd like to poll a database and get the table contents, as well as the field
names from that table. I've been to php.net but this time I cannot find
something helpful.
I can get the data,...
|
by: Philip D Heady |
last post by:
Ok, as some of you may know I'm an Oracle newbie w/ PHP. I'd rather use
MySQL but at the office here we use Oracle and boy do I have alot to learn.
I'm starting to hate it after using MySQL!!
...
|
by: madsgormlarsen |
last post by:
Hi
I need to test a field(colum) in a SQL database for for NULL values,
and have done so in this way.
$query = "SELECT j FROM Andersen";
$result = mysql_query($query, $link_id);
$query_data...
|
by: dog |
last post by:
I've seen plenty of articles on this topic but none of them have been
able to solve my problem.
I am working with an Access 97 database on an NT4.0 machine, which has
many Access reports.
I...
|
by: Dan V. |
last post by:
I would like to create a 2D string list (2D ArrayList ???). I would like to
pass in a table or query as a parameter and have both columns transform into
a 2D ArrayList. When I sort the one...
| |
by: Fredrik Rodin |
last post by:
All,
I've been looking around for a solution to my problem for a couple of days
now.
In short, here's my situation:
1.
I'm getting a result from a component back as a datatable and I have...
|
by: Haydnw |
last post by:
Hi,
I'd like to put a load of database results (several rows for 5 fields) into
a two-dimensional array. Now, this may be a really stupid question, but can
someone give me a pointer for how to...
|
by: Michael Seele |
last post by:
hi!
i need a list of all primary keys in my database! for this reson i build
these sql-statement:
/SELECT
pg_class.relname AS tableName,
pg_constraint.conname AS pkName,
pg_constraint.conkey AS...
|
by: max |
last post by:
Hello,
I am a newbye, and I'm trying to write a simple application.
I have five tables with three columns; all tables are identical; I need to
change some data in the first table and let VB...
|
by: harvey |
last post by:
How do I make PHP create a database for mysql please?
I can see how to make tables and I have read all the documents
I can find but I don't understand how to make the database itself.
All...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |