473,385 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Returning variables

Odisey
14
What is wring with this?

Expand|Select|Wrap|Line Numbers
  1. <?php  #Color instrument vars
  2.        # ODC August 4, 2008
  3.  
  4. require_once ('??????.php'); //Connect to database  RESET TO SAFE PATH ONCE IT FUNCTIONS
  5.  
  6. // Define variables
  7.  
  8. $var1 = "Hello"; 
  9.  
  10. // Make selection  
  11.  
  12. $query = "SELECT images FROM movie_images ORDER BY RAND() LIMIT 3";
  13. $result = mysql_query($query);
  14.  
  15. // Table
  16.  
  17. if ($result) {
  18.     $row = mysql_fetch_array ($result, MYSQL_ASSOC);
  19.     $s1 = $row[0];
  20.     $s2 = $row[1];
  21.     $s3 = $row[2];
  22.  
  23.  
  24. echo '<p>'. $s1 . '</p>';
  25. echo '<p>'. $s2 . '</p>';
  26. echo '<p>'. $s3 . '</p>';
  27. echo '<p>'. $var1 . '</p>';
  28. }
  29.  
  30.  
  31.  
  32. mysql_close(); // Close database connection
  33.  
  34. ?>
  35.  
  36.  
  37.  

Thank you!
Aug 4 '08 #1
6 1324
Markus
6,050 Expert 4TB
We don't guess.

Please be more descriptive.

What happens? What doesn't happen?
Aug 4 '08 #2
Odisey
14
The test variable Hello prints.... Other than that nothing happens...


Nothing obviously wrong with the syntax?


Thatnk you,
Marc
Aug 4 '08 #3
Markus
6,050 Expert 4TB
The test variable Hello prints.... Other than that nothing happens...


Nothing obviously wrong with the syntax?


Thatnk you,
Marc
You should always do some error checking; add an ELSE to your IF and an OR DIE() to your mysql query
Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT images FROM movie_images ORDER BY RAND() LIMIT 3";
  2. $result = mysql_query($query) or die(mysql_error());
  3.  
  4. // Table
  5.  
  6. if ($result) {
  7.     $row = mysql_fetch_array ($result, MYSQL_ASSOC);
  8.     $s1 = $row[0];
  9.     $s2 = $row[1];
  10.     $s3 = $row[2];
  11.  
  12.  
  13. echo '<p>'. $s1 . '</p>';
  14. echo '<p>'. $s2 . '</p>';
  15. echo '<p>'. $s3 . '</p>';
  16. echo '<p>'. $var1 . '</p>';
  17. } else {
  18. echo 'There was a problem...';
  19. }
Please remember to use code tags when posting in the forum!
Aug 4 '08 #4
Odisey
14
I usually do.

It prints the test var Hello..... Nothing else...


The error message does not print.
Aug 4 '08 #5
pbmods
5,821 Expert 4TB
Heya, Odisey.

There might be no error; your query might just have returned no results.
Aug 5 '08 #6
Odisey
14
There is one that is there.... Look at ASSOC. It should be NUM.

There are results... 8 AMF.


TYFR
Aug 5 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: nielson | last post by:
I have a class which contains (1) a class variable and (2) a method (e.g., methodA) which returns a reference to the class variable. If the variable has been assigned a value by a constant...
7
by: Dr John Stockton | last post by:
What are the best ways of returning multiple results from a subroutine ? I've been using ... return } which is inelegant. I'm used to Pascal's procedure X(const A, B : integer; var C, D :...
17
by: Roland Hall | last post by:
Is there a way to return multiple values from a function without using an array? Would a dictionary object work better? -- Roland Hall /* This information is distributed in the hope that it...
8
by: briforge | last post by:
I am writing a program for the Palm OS in c++. I have already posted this to a palm development forum but I'm desperate for a fix, so I hope this cross-post isn't offensive. My program is...
1
by: Todd Peterson | last post by:
I'm a newbie to DB2 and am trying to figure out how to write a stored procedure, using dynamic SQL statements to return a result set. I believe the majority of the hurdles I have been facing might...
1
by: Ben | last post by:
I have a Tabular form bound to a table. The purpose of this form is to get times from a timer and record them in a field. The timer dumps the time automatically through a serial port. When the time...
6
by: Generic Usenet Account | last post by:
Is it okay to return a local datastructure (something of type struct) from a function, as long as it does not have any pointer fields? I think it is a bad idea, but one of my colleagues does not...
8
by: howa | last post by:
from PHP manual, it said: Do not use return-by-reference to increase performance, the engine is smart enough to optimize this on its own ------------------ Why?
1
by: krishna81m | last post by:
In the following code, I am trying to return a char, a char* (a type of non-const without using new, what do we call this type of pointer?) and char* created using new operator. What I do not know at...
2
by: Andy B | last post by:
I need to make a class and not quite sure how to go about doing this part. I want the class to take user input, build a dataset based on that input and then return it from the class so it can be...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.