Hi. I am very new with php. can you help me with this:
This code is printing part of the string: image and image_id, but gameandtoyname and pricetype NO. What i am doing wrong? any help?
<?php
$sql = "SELECT gameandtoyname,pricetype * FROM dollsimage, dolls where dollsimage.image_id=dolls.image_id";
$sql = "SELECT * FROM dollsimage ORDER BY image_date DESC";
$result = mysql_query ($sql, $conn);
if (mysql_num_rows($result)>0) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$i++;
$str .= $i.". ";
$str .="<img border=\"1\" height=\"90\" width=\"100\" src=\"imagedolls.php?act=view&iid=".$row["image_id"]." ".$row["gameandtoyname"]." ".$row["pricetype"]." \"></a> ";
}
print $str;
}
?>
15 2576
Only the last query is executed, because you assigned the last SELECT string to the same variable ($sql) as the first SELECT string (also in variable $sql).
Ronald :cool:
Only the last query is executed, because you assigned the last SELECT string to the same variable ($sql) as the first SELECT string (also in variable $sql).
Ronald :cool:
Hi and thanks.
If i use 2 differentes variables for SELECT, i will have to use 2 differents variables for the query. How could i use only one for the same condition and print only one string?
Please help me! it is tricky and i have being using different thing but it give me errors.
Combine the 2 queries into one, selecting columns from both tables in 1 SELECT statement. Such as in this sample: - SELECT fielda, fieldb, fieldc, fieldd
-
FROM table_1, table_2
-
WHERE ......
Ronald :cool:
Combine the 2 queries into one, selecting columns from both tables in 1 SELECT statement. Such as in this sample: - SELECT fielda, fieldb, fieldc, fieldd
-
FROM table_1, table_2
-
WHERE ......
Ronald :cool:
Trying this way, it give me this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in on line 57
it is because i am missing something in the query?
Show the code regarding the query and the processing of the results WITHIN [PHP] TAGS!
Ronald :cool:
Show the code regarding the query and the processing of the results WITHIN [PHP] TAGS!
Ronald :cool:
<?php
$sql = ("SELECT gameandtoyname,pricetype
* FROM dollsimage, dolls
ORDER BY image_date DESC
where dollsimage.image_id= dolls.image_id");
$result = mysql_query ($sql, $conn);
if (mysql_num_rows($result)>0) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$i++;
$str .= $i.". ";
$str .="<img border=\"1\" height=\"90\" width=\"100\" src=\"imagedolls.php?act=view&iid=".$row["image_id"]."".$row["gameandtoyname"]."".$row["pricetype"]." \"></a> ";
}
print $str;
}
?>
Now I explicitely requested you to put your code between tags!!
Obviously you refuse to fulfill such a simple request, even though it is in the POSTING GUIDELINES!!
Therefore I feel no great urge to continue this discussion any further.
Ronald :cool:
Now I explicitely requested you to put your code between tags!!
Obviously you refuse to fulfill such a simple request, even though it is in the POSTING GUIDELINES!!
Therefore I feel no great urge to continue this discussion any further.
Ronald :cool:
Sorry Sir. I understand the php tags are: <?php ?>
sorry again.
Still can yuo help Me?....?
<?php
$sql = ("SELECT gameandtoyname,pricetype
* FROM dollsimage, dolls
ORDER BY image_date DESC
where dollsimage.image_id= dolls.image_id");
$result = mysql_query ($sql, $conn);
if (mysql_num_rows($result)>0) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$i++;
$str .= $i.". ";
$str .="<img border=\"1\" height=\"90\" width=\"100\" src=\"imagedolls.php?act=view&iid=".$row["image_id"]."".$row["gameandtoyname"]."".$row["pricetype"]." \"></a> ";
}
print $str;
}
?>
Sorry now is into tags
[PHP]
<?php
$sql = ("SELECT gameandtoyname,pricetype
* FROM dollsimage, dolls
ORDER BY image_date DESC
where dollsimage.image_id= dolls.image_id");
$result = mysql_query ($sql, $conn);
if (mysql_num_rows($result)>0) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$i++;
$str .= $i.". ";
$str .="<img border=\"1\" height=\"90\" width=\"100\" src=\"imagedolls.php?act=view&iid=".$row["image_id"]."".$row["gameandtoyname"]."".$row["pricetype"]." \"></a> ";
}
print $str;
}
?>
[/PHP]
Ok. Just to make it easier to read, I have assigned the $row values to separate php variables, so it is easier to include in the output string. For the same reason I have also replaced the \"by a simple single slash. That is no criticism, just makes it somewhat easier to read.
Now what was wrong was, that you had in your select statement an * without separating comma, so there was an sql error.
Also I saw that you forgot to include the field image_date in your select, so I added that. I do not know from which table you want to select image_date, but I assumed from table dollsimage, so you'll have yo change that if not correct.
That brings me to the following code snippet for you.[php]<?php
$sql = ("SELECT gameandtoyname, pricetype, dollsimage.image_id, dollsimage.image_date,
FROM dollsimage, dolls
ORDER BY image_date DESC
WHERE dollsimage.image_id = dolls.image_id");
$result = mysql_query ($sql, $conn);
$str = "";
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$i++;
$image_id = $row["image_id"];
$gameandtoyname = $row["gameandtoyname"];
$pricetype = $row["pricetype"];
$str .="$i. <img border='1' height='90' width='100' src='imagedolls.php?act=view&iid=$image_id$gameand toyname$pricetype'></a> ";
print $str;
}
print $str;
}
?>[/php]
Let me know if this works (after you checked that the image_date is selected from the correct table).
Ronald :cool:
Ok. Just to make it easier to read, I have assigned the $row values to separate php variables, so it is easier to include in the output string. For the same reason I have also replaced the \"by a simple single slash. That is no criticism, just makes it somewhat easier to read.
Now what was wrong was, that you had in your select statement an * without separating comma, so there was an sql error.
Also I saw that you forgot to include the field image_date in your select, so I added that. I do not know from which table you want to select image_date, but I assumed from table dollsimage, so you'll have yo change that if not correct.
That brings me to the following code snippet for you.[php]<?php
$sql = ("SELECT gameandtoyname, pricetype, dollsimage.image_id, dollsimage.image_date,
FROM dollsimage, dolls
ORDER BY image_date DESC
WHERE dollsimage.image_id = dolls.image_id");
$result = mysql_query ($sql, $conn);
$str = "";
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$i++;
$image_id = $row["image_id"];
$gameandtoyname = $row["gameandtoyname"];
$pricetype = $row["pricetype"];
$str .="$i. <img border='1' height='90' width='100' src='imagedolls.php?act=view&iid=$image_id$gameand toyname$pricetype'></a> ";
print $str;
}
print $str;
}
?>[/php]
Let me know if this works (after you checked that the image_date is selected from the correct table).
Ronald :cool:
Sir, still i get this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C: on line 67
Could you please help me with this. Thanx
[PHP]
<?php
$sql = ("SELECT gameandtoyname, pricetype, dollsimage.image_id, dollsimage.image_date,
FROM dollsimage, dolls
ORDER BY image_date DESC
WHERE dollsimage.image_id = dolls.image_id");
$result = mysql_query ($sql, $conn);
$str = "";
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$i++;
$image_id = $row["image_id"];
$gameandtoyname = $row["gameandtoyname"];
$pricetype = $row["pricetype"];
$str .="$i. <img border='1' height='90' width='100' src='imagedolls.php?act=view&iid=$image_id$gameand toyname$pricetype'></a> ";
print $str;
}
print $str;
}
?>
[/PHP]
Of course that code does not work, Before it you'll have to connect to your server and your database. Such as:
[php]
$con = mysql_connect("xx", "yy", "zz")
or die("Connect error: " . mysql_error());
mysql_select_db("dd")
or die("Db select error: " . mysql_error());
[/php] Don't forget to change the xx, yy, zz and dd to the actual values!
After that you put the select code.
Ronald :cool:
Of course that code does not work, Before it you'll have to connect to your server and your database. Such as:
[php]
$con = mysql_connect("xx", "yy", "zz")
or die("Connect error: " . mysql_error());
mysql_select_db("dd")
or die("Db select error: " . mysql_error());
[/php] Don't forget to change the xx, yy, zz and dd to the actual values!
After that you put the select code.
Ronald :cool:
Sir: I do have the connection. here is the rest of the code:
thankx alot.
[PHP]
<?php
// database connection
$conn = mysql_connect("localhost", "root") OR DIE (mysql_error());
@mysql_select_db ("products", $conn) OR DIE (mysql_error());
// browse the file and click the submit button
if ($_FILES) {
$image_types = Array ("image/bmp",
"image/jpeg",
"image/pjpeg",
"image/gif",
"image/x-png");
$userfile = addslashes (fread (fopen ($_FILES["userfile"]["tmp_name"], "r"), filesize ($_FILES["userfile"]["tmp_name"])));
$file_name = $_FILES["userfile"]["name"];
$file_size = $_FILES["userfile"]["size"];
$file_type = $_FILES["userfile"]["type"];
if (in_array (strtolower ($file_type), $image_types)) {
$sql = "INSERT INTO dollsimage (image_type, image, image_size, image_name, image_date) ";
$sql.= "VALUES (";
$sql.= "'{$file_type}', '{$userfile}', '{$file_size}', '{$file_name}', NOW())";
@mysql_query ($sql, $conn);
Header("Location:".$_SERVER["PHP_SELF"]);
exit();
}
}
// view or remove
if ($_GET) {
$iid = $_GET["iid"];
$act = $_GET["act"];
switch ($act) {
case rem:
$sql = "DELETE FROM dollsimage WHERE image_id=$iid";
@mysql_query ($sql, $conn);
Header("Location:./textimage4.php");
exit();
break;
default:
print "<img src=\"imagedolls.php?iid=$iid\">";
break;
}
}
?>
<form method="post" enctype="multipart/form-data">
Select Image File: <input type="file" name="userfile" size="40"><input type="submit" value="submit">
</form>
<?php
$sql = ("SELECT gameandtoyname, pricetype, dollsimage.image_id, dollsimage.image_date,
FROM dollsimage, dolls
ORDER BY image_date DESC
WHERE dollsimage.image_id = dolls.image_id");
$result = mysql_query ($sql, $conn);
$str = "";
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$i++;
$image_id = $row["image_id"];
$gameandtoyname = $row["gameandtoyname"];
$pricetype = $row["pricetype"];
$str .="$i. <img border='1' height='90' width='100' src='imagedolls.php?act=view&iid=$image_id$gameand toyname$pricetype'></a> ";
print $str;
}
print $str;
}
?>
[/PHP]
Imagedolls.php :
[PHP]
<?php
// database connection
$conn = mysql_connect("localhost", "root") OR DIE (mysql_error());
@mysql_select_db ("products", $conn) OR DIE (mysql_error());
$sql = "SELECT * FROM dollsimage WHERE image_id=".$_GET["iid"];
$result = mysql_query ($sql, $conn);
if (mysql_num_rows ($result)>0) {
$row = @mysql_fetch_array ($result);
$image_type = $row["image_type"];
$image = $row["image"];
Header ("Content-type: $image_type");
print $image;
}
?>
[/PHP]
I cannot see the error, but it is late, so I could overlook it. You could add the following line after the query to see if it returns an error message:
[php]if (!$result) {
die('Invalid query: ' . mysql_error());
}[/php]
Ronald :cool:
I cannot see the error, but it is late, so I could overlook it. You could add the following line after the query to see if it returns an error message:
[php]if (!$result) {
die('Invalid query: ' . mysql_error());
}[/php]
Ronald :cool:
Sir. now it brings this error:
thankx alot.
Invalid query: 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 'FROM dollsimage, dolls ORDER BY image_date DESC
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Batista, Facundo |
last post by:
One detail I found, don't now if it's ok:
Python 2.1.1 (#4, Mar 8 2002, 12:32:24)
on sunos5
>>> a = 'ñ'
>>> a
'\xf1'
>>> print a
ñ
|
by: Karl Scalet |
last post by:
Hi,
quite often there is a need to just print out the items of a list.
that would be nice, except prt() does not exist, and print is a
statement not a function, hence cannot replace prt as...
|
by: David Bolen |
last post by:
I ran into this strange behavior when noticing some missing spaces in
some debugging output. It seems that somewhere in the print
processing, there is special handling for string contents that...
|
by: François Pinard |
last post by:
Hi, people. I hope someone would like to enlighten me.
For any application handling Unicode internally, I'm usually careful
at properly converting those Unicode strings into 8-bit strings before...
|
by: vijay |
last post by:
Hello,
As the subject suggests, I need to print the string in the reverse
order. I made the following program:
# include<stdio.h>
struct llnode
{
char *info;
|
by: bearophileHUGS |
last post by:
There is/was a long discussion about the replacement for print in
Python 3.0 (I don't know if this discussion is finished):
http://mail.python.org/pipermail/python-dev/2005-September/055968.html
...
|
by: Ju Hui |
last post by:
I want to print 3 numbers without blank.
>>> for x in range(3):
.... print x
....
0
1
2
>>> for x in range(3):
.... print x,
....
|
by: A.M |
last post by:
Hi,
I found print much more flexible that write method. Can I use print instead
of file.write method?
Thank you,
|
by: James J. Besemer |
last post by:
I would like to champion a proposed enhancement to Python. I describe the
basic idea below, in order to gage community interest. Right now, it's only
an idea, and I'm sure there's room for...
|
by: mrstephengross |
last post by:
I would like to get the results of a print operation placed in a
string. For instance, you can very easily create a list and print it
to stdout:
x =
print x # Will print
What if I want the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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: 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: 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...
| |