473,394 Members | 1,893 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,394 software developers and data experts.

issue with displaying data with php from mysql

65
Hi All,

The following script will display the grid, with its headers but will not display any data. Im sure ive made a mistake in the syntax somewhere but i can see the wood for the trees.

Ive ran the sql statement directly in mysql and it gives me results.

any help is greatly appreciated

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  2.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6.     <title>CG0119 mysql - studentList.php</title>
  7. </head>
  8.  
  9. <body>
  10. <h1>Student Listing</h1>
  11.  
  12. <?php
  13.  
  14. // Connect to the Oracle database
  15. $link = mysqli_connect("localhost","root","root","university")
  16.  or die("ERROR: Could not connect : " . mysql_error());
  17.  
  18. // Set up a query to select the required fields and records
  19. $result = mysqli_query($link, "SELECT studentCode, forename, surname, startYear, typeDesc FROM student, studyType WHERE student.studyTypeID = studyType.studyTypeID")
  20. or die("ERROR:query failed (Student) - " . mysql_error());
  21.  
  22. $studentResult = mysqli_query($link, $sql);
  23. ?>
  24.  
  25. <!-- Move out of PHP mode and start the table tags (note you
  26. could have stayed in PHP mode and achieved the same
  27. result by placing these tags within echo statements. -->
  28.  
  29. <table width="70%" border="1">
  30. <tr>
  31. <td width="15%"><strong>Student Code</strong></td>
  32. <td width="25%"><strong>Surname</strong></td>
  33. <td width="25%"><strong>Forename</strong></td>
  34. <td width="20%"><strong>Study Type</strong></td>
  35. <td width="15%"><strong>Start Year</strong></td>
  36. </tr>
  37.  
  38. <?php
  39.  
  40. // For every row that was returned by the query, do something.
  41. // In this example, display data from each row within an XHTML table.
  42.  
  43. // NOTE: The array keys (the field names are the array keys, the values are the field values returned by the SQL query) 
  44.  
  45.                echo "<tr>\n";
  46.                echo "<td>&nbsp;</td>\n";
  47.                echo "<td>".$studentResult['studentCode']."</td>\n";
  48.                echo "<td>".$studentResult['surname']."</td>\n";
  49.                echo "<td>".$studentResult['forename']."</td>\n";
  50.                echo "<td>".$studentResult['studyType']."</td>\n";
  51.                echo "<td>".$studentResult['startYear']."</td>\n";
  52.                echo "</tr>\n";    
  53.  
  54. // General clean-up of resources (i.e. memory).
  55.  
  56. mysqli_free_result($studentResult);
  57. mysqli_close($link);
  58.  
  59. ?>
  60.  
  61. </body>
  62. </html>
  63.  
Oct 14 '09 #1
9 1919
Dormilich
8,658 Expert Mod 8TB
you should get some useful error messages
#22 $sql not defined
#47-51 (?) $studentResult is not an array

and of course you don't fetch data anywhere...
Oct 14 '09 #2
whitep8
65
thank you for this, i get no error messages at all.

ill take a look and try to fix
Oct 14 '09 #3
Dormilich
8,658 Expert Mod 8TB
@whitep8
this may be due to suppressed error reporting
Oct 14 '09 #4
whitep8
65
i think im having a thick morning.

ive added

error_reporting(E_ALL);
ini_set('display_errors', '1');

into php.ini

you know any good labotomy doctors?
Oct 14 '09 #5
Dormilich
8,658 Expert Mod 8TB
@whitep8
shall I recommend a good decapitator?
Oct 14 '09 #6
whitep8
65
lol i think thats a good idea.

it should be in .htaccess shouldnt it
Oct 14 '09 #7
Dormilich
8,658 Expert Mod 8TB
@whitep8
although you can place it there I rather recommend it to be in the PHP file* (it is easyto forget that PHP relevant code is placed in .htaccess and then you have the time of your life finding the setting)

* - especially if it is temporary
Oct 14 '09 #8
whitep8
65
Ok, i dont think im going totally mad.

I have created a php.ini AND a php5.ini file. both with error activation.

I have simplified everything right down to the following but it still shows nothing.

its so annoying

Expand|Select|Wrap|Line Numbers
  1.  <?php
  2.  
  3. // Connect to the Oracle database
  4. $connection = mysql_connect("localhost","root","root","university")
  5.  or die("ERROR: Could not connect : " . mysql_error());
  6.  
  7. // Set up a query to select the required fields and records
  8. $sql = "SELECT studentCode FROM student";
  9.  
  10.  
  11. echo $sql;
  12.  
  13. $query = mysql_query($sql);
  14.  
  15. echo $query;
  16. while ($row = mysql_fetch_array($query))    {
  17.  
  18.                echo "<p>", $row['studentCode'];
  19. }
  20.  
  21.  
  22. ?>
Oct 14 '09 #9
whitep8
65
sorted

error reporting is switched on again. im using MAMP. silly thing, stupid me
Oct 14 '09 #10

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

Similar topics

3
by: JP SIngh | last post by:
Hi All We have an ASP application which tracks holidays for our employees. When the user logs in we store thier username in a session variable and use that variable when displaying and adding...
1
by: Dave Posh | last post by:
I seem to be having a problem displaying time stored in mysql. The format stored in the database is 13:15:05. The database data type is time. I'm using asp vbscript and sql to retrieve the time...
0
by: Matt | last post by:
Hi I'm have difficulty displaying images that are stored in a MySQL database. I've tried using the odbc.net provider, the ByteFX provider and the MySQLDriverCS one but can't seem to get the...
1
by: mpar612 | last post by:
Hi everyone, I'm not sure if this is asking too much or not. I am trying to get the following PHP code to work on my website. It utilizes PHP 5, MySQL 4.1 and the PEAR DB module. I am...
2
by: matthud | last post by:
<?php //MAKE IT SAFE $chunk = $_POST; $title = $_POST; $url = $_POST; $tags = $_POST; $user = $_POST; $safe_chunk = mysql_real_escape_string(htmlentities($chunk)); $safe_title =...
13
by: David W. Fenton | last post by:
I've been struggling the last two days with something I thought was very easy, which is to open a web page with a form on it and populate the form with data passed in a query string (either POST or...
2
by: Colleen Robledo, MLIS | last post by:
Hello, I'm still pretty new to PHP and MySQL, and have a PHP scripting question. If I'm querying DATE info from a MySQL database, and displaying it with PHP echo statements... is there a PHP...
10
by: Lloyd Harold | last post by:
I'm very new to PHP and attempting to put together a simple script for retrieving MySQL data of personal records. The MySQL table I'm using consists of: 0: id 1: name 2: location (an integer...
1
by: gubbachchi | last post by:
Hi, For my project I have a "add" button, upon clicking it, it will take the user to next page where there will be a text box and list of data displayed below it which is fetched from mysql...
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: 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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
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...
0
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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 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.