|
 |
|
 |
 |
|
06-17-2007, 12:10 AM
|
#16 (permalink)
|
|
Jack of all trades
Join Date: Feb 2005
Location: Los Angeles
Posts: 595
|
The = operator is your friend
__________________
Stop intellectual property from infringing on me
|
|
|
06-17-2007, 10:41 AM
|
#17 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
Quote:
Originally Posted by teknomage1
The = operator is your friend
|
For what?
Many Thanks,
__________________
Many Thanks, in advance!
Salchester.
The Future Is Here - Are You Ready?
|
|
|
06-17-2007, 02:53 PM
|
#18 (permalink)
|
|
Senior Contributor
Join Date: Mar 2005
Posts: 635
|
Quote:
Originally Posted by Salchester
how do you put information into the array using variables
|
Quote:
Originally Posted by teknomage1
The = operator is your friend
|
there's nothing more to say about it.
P.S. Salchester, how old are you?
__________________

UT: Ultra-kill... God like!
|
|
|
06-18-2007, 01:22 AM
|
#19 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
Insert Table Data into Array
DJMaze,
That's It? But how do I store the data in a variable in the array like following Visual Basic code does?
The name, species, & sex variables are linked with the array on the 6th line.
Code:
Private Type details
name As String
species As String
sex As String
End Type
Dim record() As details
Private Sub Form_Load()
ReDim record(0)
End Sub
Private Sub lblNext_Click()
ReDim Preserve record(UBound(record) + 1)
record(UBound(record)).name = txtName.Text
record(UBound(record)).species = txtSpecies.Text
record(UBound(record)).sex = txtSex.Text
MsgBox record(1).name
End Sub
Many Thanks,
P.S I'm 20 Why?
__________________
Many Thanks, in advance!
Salchester.
The Future Is Here - Are You Ready?
|
|
|
06-18-2007, 01:53 AM
|
#20 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
Insert Table Data into Array
DJMaze,
The following code doesn't work, nothing gets display from the database.
Why is this?
Code:
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("WB", $con);
$result = mysql_query("select * from Birds");
// alternatively, you could use mysql_fetch_assoc if you wanted
// the array to be keyed by the field name
while ($array = mysql_fetch_assoc($result))
{
echo $array[0]['Name'];
}
?>
Many Thanks,
__________________
Many Thanks, in advance!
Salchester.
The Future Is Here - Are You Ready?
|
|
|
06-18-2007, 02:45 AM
|
#21 (permalink)
|
|
Senior Contributor
Join Date: Mar 2005
Posts: 635
|
Well sometimes your question are like from a 12 year old in my feeling.
It's not to downgrade you, but some questions emply that you didn't learn a thing from answers due to the fact that basics like operator and associative arrays are missing in your knowledge.
PHP Code:
header('Content-type: text/plain');
$records = array(); while ($array = mysql_fetch_assoc($result)) { $records[] = $array; }
print_r($records);
__________________

UT: Ultra-kill... God like!
|
|
|
06-18-2007, 03:07 AM
|
#22 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
|
Just a quick out of thoughts rewrite of your VB thingy there into PHP, Absolutely no guarentie it will work of any sort
PHP Code:
<?
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("WB", $con);
class details {
var $name;
var $species;
var $sex;
function details($id){
$result = mysql_query("select * from Birds where id = '$id'");
if($array = mysql_fetch_array($result)){
$this->name = $array['name'];
$this->species = $array['species'];
$this->sex = $array['sex'];
}
}
function show(){
echo "<table border=1 cellspacing=0 cellpadding=0>
<tr><td>" . $this->name . "</td>
<tr><td>" . $this->species . "</td>
<tr><td>" . $this->sex. "</td></tr></table>";
}
}
class record{
var $items = array();
var $count;
function record(){
$this->count = 0;
$result = mysql_query("select id from Birds");
while ($array = mysql_fetch_array($result)) {
$this->items[$this->count++] = new details($array['id']);
}
}
function show(){
for($i=0; $i < $this->count; $i++)
$this->items[$i]->show();
}
}
$my_record = new record();
$my_record->show();
?>
For a refference, you can look at the Object Oriented PHP article.
And DjMs question regarding your age, is of some relevence, since some of your questions seems to come from one who dosn't grasp what is going on, and feel it is easier to ask for a solution than to piece together one from previus explanations.
|
|
|
06-18-2007, 03:20 AM
|
#23 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
Insert Table Data into Array
DJMaze,
How come the following doesn't work, when code is included from previous posts?
Code:
<?php
header('Content-type: text/plain');
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("WB", $con);
$result = mysql_query("select * from Birds");
$records = array();
while ($array = mysql_fetch_assoc($result))
{
$records[0]['Name'];
}
print_r($records);
?>
__________________
Many Thanks, in advance!
Salchester.
The Future Is Here - Are You Ready?
|
|
|
06-18-2007, 05:25 AM
|
#24 (permalink)
|
|
Senior Contributor
Join Date: Mar 2005
Posts: 635
|
Do you really want me to reply?
Did you ever try my code (and that from redhead and sde) ?
Did you see the output of that code?
Why did you modify my code?
Can you please read, copy and understand it all before screwing around with it?
__________________

UT: Ultra-kill... God like!
|
|
|
06-18-2007, 08:30 AM
|
#25 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
Insert Table Data into Array
JMaze,
Quote:
|
Do you really want me to reply?
|
Yes. Please
Quote:
|
Did you ever try my code (and that from redhead and SDE)?
|
Yes, the code I posted previously was from help by SDE, only it don't work, nothing gets displayed. Somethings wrong, but what?
As far as Redhead code goes, that doesn't work either, I keep getting greeted with the following error message.
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Documents and Settings\Dale Piper\Desktop\xampplite\htdocs\Array.php on line 36
Quote:
|
Did you see the output of that code?
|
Yes. See Above
Quote:
|
Why did you modify my code?
|
The code you posted didn't include PHP opening/closing tags, nor did it declare where the data was coming from. e.g. Database, Table etc.
Quote:
|
Can you please read, copy and understand it all before screwing around with it?
|
Understanding it, come with playing around. I am a hands on person, and mucking around with things at finding out how it works etc, is the way I learn. You can change the way people learn. We all learn in different ways, at within different time frames.
Many Thanks,
__________________
Many Thanks, in advance!
Salchester.
The Future Is Here - Are You Ready?
|
|
|
06-18-2007, 09:16 AM
|
#26 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
Insert Table Data into Array
DJMaze,
How come when i change the following code (In Bold)
from:
Code:
$records[] = $array;
to:
Code:
$records[1] = $array;
The the last record entered gets displayed as record 0 in stead of the second record being displayed?
Code:
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("WB", $con);
$result = mysql_query("select * from Birds");
header('Content-type: text/plain');
$records = array();
while ($array = mysql_fetch_assoc($result))
{
$records[0] = $array;
}
print_r($records);
?>
__________________
Many Thanks, in advance!
Salchester.
The Future Is Here - Are You Ready?
|
|
|
06-18-2007, 09:42 AM
|
#27 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
|
Quote:
Code:
$records[0] = $array;
|
You are overwriting index '0' of your array constantly, look at DjM code, it is not indexing a specific location when adding to the array.
|
|
|
06-18-2007, 10:35 AM
|
#28 (permalink)
|
|
Senior Contributor
Join Date: Mar 2005
Posts: 635
|
Quote:
Originally Posted by Salchester
As far as Redhead code goes, that doesn't work either, I keep getting greeted with the following error message.
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Documents and Settings\Dale Piper\Desktop\xampplite\htdocs\Array.php on line 36
|
That one is easy to debug.
PHP Code:
$result = mysql_query("select * from Birds");
if (!$result) { die(mysql_error()); }
And i want you to tell me what this code does, step by step.
__________________

UT: Ultra-kill... God like!
|
|
|
06-18-2007, 10:54 AM
|
#29 (permalink)
|
|
Salchester
Join Date: Jul 2005
Location: In a house
Posts: 230
|
Insert Table Data into Array
Quote:
Originally Posted by redhead
You are overwriting index '0' of your array constantly, look at DjM code, it is not indexing a specific location when adding to the array.
|
Redhead,
How do I change it so it does index a specific location when adding an entry to the array?
Resulting in each record (Name,Species, Sex) having its own location within the array, starting at 0.
This will be useful as I will need it for later.
Many Thanks,
__________________
Many Thanks, in advance!
Salchester.
The Future Is Here - Are You Ready?
|
|
|
06-19-2007, 05:18 AM
|
#30 (permalink)
|
|
Senior Contributor
Join Date: Mar 2005
Posts: 635
|
Quote:
Originally Posted by Salchester
JThe code you posted didn't include PHP opening/closing tags, nor did it declare where the data was coming from. e.g. Database, Table etc.Understanding it, come with playing around. I am a hands on person, and mucking around with things at finding out how it works etc, is the way I learn. You can change the way people learn. We all learn in different ways, at within different time frames.
|
It didn't have open/close tags because it shouldn't need that at all.
If you did compare codes, you would have noticed my code was just a portion of all the code.
Sorry but it looks like your way of learning stuff is bad. You haven't learn a thing so far.
If you did, tell me what you have learned, code line by code line. Else i don't see any use of replying to you again and again and again by any of us.
__________________

UT: Ultra-kill... God like!
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 05:06 PM.
|
Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle
|
 |
|