Welcome! Log In Create A New Profile

Advanced

Chapter 13 - Displaying data from database

Posted by kreason_77840070 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Chapter 13 - Displaying data from database
February 16, 2013 08:30PM
I copied the code below exactly as from the html file but when I run the file I get the following error: "Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in D:\EasyPHP-5.3.3\www\database.php on line 16"
I'v created the database and tried connecting to it. Thats fine, its only when i try to display data that I have a problem. Any suggestions?

Language: PHP
<?PHP   $user_name = "root"; $password = ""; $database = "addressbook"; $server = "127.0.0.1";   $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle);   if ($db_found) {   $SQL = "SELECT * FROM tb_address_book"; $result = mysql_query($SQL);   while ($db_field = mysql_fetch_assoc($result)) { print $db_field[';ID';] . "<BR>"; print $db_field[';First_Name';] . "<BR>"; print $db_field[';Surname';] . "<BR>"; print $db_field[';Address';] . "<BR>"; }   mysql_close($db_handle);   } else { print "Database NOT Found "; mysql_close($db_handle); }   ?>

http://capetown-airport.co.za/
avatar
Mac
Re: Chapter 13 - Displaying data from database
February 18, 2013 07:39AM
The sql query is incorrect, so mySQL does not understand it, e,g, wrong table name, wrong columns etc. Case counts.
avatar Re: Chapter 13 - Displaying data from database
February 18, 2013 08:54AM
i've similar problem but mine it does post to database but output is not what i expect it keeps saying table aready exist whilst i put condition that say if already exist it must populate it but if not it must first create the table " i'll put src code this afternoon".

gbakamela [77234715]
avatar
Mac
Re: Chapter 13 - Displaying data from database
February 18, 2013 11:49AM
Why do you want to write code that creates a table???? No need for that. Create your table by hand and write code that uses an existing table.
Re: Chapter 13 - Displaying data from database
February 18, 2013 12:55PM
my thought exactly Mac. personally i would rather create a table by hand.... if you are still getting a "table doesn't exist error" check if you are referencing it with a correct name.
Re: Chapter 13 - Displaying data from database
February 18, 2013 01:49PM
Thanks for the input. Silly error on my behalf. I named the table incorrectly in php myadmin. Good to learn the error this gives tho!

http://capetown-airport.co.za/
avatar
Mac
Re: Chapter 13 - Displaying data from database
February 18, 2013 02:59PM
A little bit worried that you are at lesson 13 already? Do not just read - run all the code...
avatar Re: Chapter 13 - Displaying data from database
February 18, 2013 06:38PM
was just trying to see if it will work the idea is to create a site where one can register as admin, user and guest user, so the admin must create tables using the site not phpmyadmin "manual"! my concern on this approach the table below after posting it doesn't show
Language: PHP
<body> <h1>My Guest Book</h1> <form action="contact.php" method="post" name="People" id="People" > <table border="1" width="400"> <tr> <td> First Name</td> <td><input type="text" name="fname"size ="43" /></td> </tr> <tr> <td> Last Name</td> <td><input type="text" name="lname"size ="43" /></td> </tr> <tr> <td> email</td> <td><input type="text" name="email"size ="43" /></td> </tr>   </table> <p><input type="submit" value="Add Contact" /></p> </form> </body>   </html>   <?php include("scripts-pvt/config.php"); //see if people table exits , if not creat $check = mysql_query("SELECT * FROM ';people'; LIMIT 0,1 "); if ($check){ // query was legal and table exist }else{ //something went wrong, so : //create the table $peoples = "CREATE TABLE people(people_id int(11) NOT NULL auto_increment,people_fname varchar (32) NOT NULL,people_lname varchar (32) NOT NULL,people_email varchar (32) NOT NULL,PRIMARY KEY (people_id))";   $results = mysql_query($peoples) or die (mysql_error()); } //query all of people $query ="SELECT * FROM people"; $result=mysql_query($query);   mysql_close(); //first row echo "<table bgcolor=';1'; cellpadding=5 width=';400'; style=';font-size:13px';>"; echo "<tr><td><H3>First Name </h3></td>"; echo "<tr><td><H3>Last Name </h3></td>"; echo "<tr><td><H3>Email </h3></td>"; echo "<tr><td><H3>Edit </h3></td>"; // second row // keeps getting the next row until are no more to get while ($row = mysql_fetch_array($result)) { // print out the contents of each row into a table echo "<tr><td>"; echo $row[';people_fname';]; echo "<tr><td>"; echo $row[';people_lname';]; echo "<tr><td>"; echo $row[';people_email';]; echo "</td><td>"; echo ';<a href ="edit.php?id=';.$row[';people_id';].';"> Edit</a>';; echo "</td><tr>"; } echo "</table>"; ?>

i cant edit details posted because as result

gbakamela [77234715]
Re: Chapter 13 - Displaying data from database
February 20, 2013 09:45PM
Lets make this a rule....DO NOT CREATE A TABLE IN YOUR PHP PAGES, create it directly in mysql database or whatever database you are using.

Language: PHP
$peoples = "CREATE TABLE people(people_id int(11) NOT NULL auto_increment,people_fname varchar (32) NOT NULL,people_lname varchar (32) NOT NULL,people_email varchar (32) NOT NULL,PRIMARY KEY (people_id))";
Re: Chapter 13 - Displaying data from database
February 21, 2013 01:36PM
It is easy to create a table from the database not on php pages.
avatar
Mac
Re: Chapter 13 - Displaying data from database
February 21, 2013 03:01PM
There you have it smiling smiley One should only create db's from pages if you offer a service, but that is already covered by apps like Cpanel when you buy webserver space. Do not reinvent the wheel.....
Re: Chapter 13 - Displaying data from database
February 21, 2013 03:52PM
mac Wrote:
-------------------------------------------------------
> A little bit worried that you are at lesson 13
> already? Do not just read - run all the code...

I started as soon as I got the cd which was a while ago and I try to push as much work as I can when I have time. I have been running all code.

http://capetown-airport.co.za/
avatar Re: Chapter 13 - Displaying data from database
February 22, 2013 08:33AM
LOLeye popping smiley I here You Guysdrinking smiley

gbakamela [77234715]
Re: Chapter 13 - Displaying data from database
February 22, 2013 10:33AM
Hi, I strongly agree never create a database or a table using code... because we have SQL GUI already there to make our lives easier believe me you wont even do that in a work place.... so you can use in this course phpMyAdmin or if you want to be more secure and advanced use MySQL Workbench, or SQLyog and some few ones out there... but I recommend to get used to SQLyog it's very good and has more functionality... but for the sake of this course you can use phpMyAdmin since we are working locally... so no hackers...lol...coolspinning smiley sticking its tongue out
Re: Chapter 13 - Displaying data from database
February 22, 2013 01:05PM
How does this "Visual Basic.NET" get to be printed on a page? i would like to understand that..




Language: HTML
<Input type = ';Checkbox'; Name = ';ch1'; value = "net" <?php print $ch1;?> >Visiual Basic.NET
avatar
Mac
Re: Chapter 13 - Displaying data from database
February 22, 2013 02:22PM
That paragraph refers to the original form - put it on the same line then read it again.

Language: PHP
// //The last thing we need to do is to print the value of the variable to the HTML form: <Input type = ';Checkbox'; Name =';ch1'; value ="net" <?PHP print $ch1; ?>>Visual Basic .NET
Re: Chapter 13 - Displaying data from database
February 27, 2013 03:10PM
Thanks guys, had the same issue as kreason_77840070 (first posting). The table name in the code was different to what i called it in phpMyAdmin. Works like a charm now.
Re: Chapter 13 - Displaying data from database
February 27, 2013 04:35PM
Hi all,

Did everyone manage to find the 'magic_quotes_gpc' text in the php.ini file?

Is there a possible reason why it would not be in the php.ini file?

Cheers
Ian
avatar Re: Chapter 13 - Displaying data from database
February 27, 2013 05:01PM
I found mine, but when I changed the value it gave some weird errors so I changed it back. What version of PHP are you running?


77928490 Wrote:
-------------------------------------------------------
> Hi all,
>
> Did everyone manage to find the 'magic_quotes_gpc'
> text in the php.ini file?
>
> Is there a possible reason why it would not be in
> the php.ini file?
>
> Cheers
> Ian
avatar Re: Chapter 13 - Displaying data from database
February 27, 2013 05:06PM
The tutorials all go by way of getting data into an array (from and to the database) before doing anything to it. Is this a security consideration or can one not manipulate data directly in the database?

Taking a JAVA example here, I know that applets in html forms are not allowed to access the database directly, but only through a database manager. This is for security reasons.
Re: Chapter 13 - Displaying data from database
February 27, 2013 10:40PM
Hi 77843835AlexB

Running EasyPHP 5.4.6
avatar
Mac
Re: Chapter 13 - Displaying data from database
February 28, 2013 08:21AM
Re: Chapter 13 - Displaying data from database
March 04, 2013 06:03AM
slowly starting to understand cool smiley Done
avatar
Mac
Re: Chapter 13 - Displaying data from database
March 04, 2013 08:16AM
77928490 Wrote:
-------------------------------------------------------
> Hi all,
>
> Did everyone manage to find the 'magic_quotes_gpc'
> text in the php.ini file?
>
> Is there a possible reason why it would not be in
> the php.ini file?
>
> Cheers
> Ian

They do not want you to play with it....!
Re: Chapter 13 - Displaying data from database
March 05, 2013 11:26AM
done and dusted.. time for the real stuff grinning smiley ..

Student number : 7803-010-2
Email and Gtalk for support : wilcovandeijl@gmail.com
Re: Chapter 13 - Displaying data from database
March 08, 2013 01:41PM
Done with databases!
avatar Re: Chapter 13 - Displaying data from database
March 17, 2013 06:06PM
I agree, rather use the GUI. One thing I do after creating a database is to export a raw copy (dump) of it before I add any values, this is incase I need to start over.

wilcovandeijl Wrote:
-------------------------------------------------------
> done and dusted.. time for the real stuff grinning smiley ..

I'm so with you wilco!

Done and dusted, roll on the good times!

____________________________________________Nazi Coder____________________________________________

I'm not antisocial, I'm just not user friendly

"It's not a bug; it's an undocumented feature!" ~ some unknown Microsoft developer
avatar Re: Chapter 13 - Displaying data from database
March 19, 2013 05:00AM
Hi there, don't know if anyone else is interested, but found the link for the PHP security blunders on sitepoint (ch 13 p 5) is no longer valid, but found a replacement here: http://www.sitepoint.com/php-security-blunders/ - looks like it covers a similar topic. Did anyone else find another link maybe?

Great tut, done with this section, security sure is hectic and needs a lot of attention when you code!
Cheers
Re: Chapter 13 - Displaying data from database
March 20, 2013 10:54AM
Very comprehensive discussion in this chapter,i so njoyed it. magic Quotes were new to me but I guess its all part and parcel of understanding how html and php works (php.ini) as well. thanks for the link 77929284. At times its best to use the GUI but if u occasionally hv to create the same db's and tables, best u keep ur scripts and clauses safe and ready for use.

..&ru..
Re: Chapter 13 - Displaying data from database
March 20, 2013 11:12AM
done. found the injection part informative.
avatar Re: Chapter 13 - Displaying data from database
March 20, 2013 11:35PM
I have always seen connecting to a database using PHP as being difficult.
This lesson shows the 3 basic steps, using the functions mysql_connect( ), mysql_select_db(), mysql_close().
The SQL statement is pretty straight forward once you have connected to the database.
You can SELECT data, INSERT new data, UPDATE data and even DELETE data.
Magic Quotes is something that I have never heard of.
I see that this is a setting that can be turned off or on. I was not aware of this setting.
I've heard about SQL Injection.
I didn't know how harmful it can be.
Re: Chapter 13 - Displaying data from database
March 21, 2013 08:49PM
A nice and easy to understand explanation of how to connect to your SQL database and how to enter data, remove data, delete data, get data from you database, or search for specific data in you database through php.

Magic quotes have been deprecated and pose a security risk when turned on:
http://php.net/manual/en/security.magicquotes.php

I thought is useful to learn about prepared statements since they are secure against SQL injections :
http://php.net/manual/en/pdo.prepared-statements.php

My code for more secure SQL queries (it is probably not that complete but at least it is a start smiling smiley ):
Language: PHP
<html> <head> <title>Secure Sql Query</title> </head> <body> <?php     $user_name = "root"; $dbpassword = "root"; $database = "databaseName"; $server = "127.0.0.1";   function safe_sql($formEntry) { if (!is_numeric($formEntry)) { $formEntry = $dbHandle-> real_escape_string($formEntry); $formEntry = htmlspecialchars($formEntry); } return $formEntry; }       if (isset($_POST[';SignUp';])) { $username = $_POST[';username';];   if(empty($username)) { print(';Please remeber to enter a username.';); } else { if ( $_POST[';password';] == $_POST[';comparePassword';] ) { $password = $_POST[';password';]; $dbHandle = new mysqli($server, $user_name, $dbpassword,$database); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { print "Connection to the Server opened, database found </br>"; $username = safe_sql($username); $password = safe_sql($password); $SQLnewSignUp = $dbHandle -> prepare(';INSERT INTO users(userrname,password) VALUES(?,?);';); $SQLnewSignUp-> bind_param(';ss';,$username,$password); $SQLnewSignUp-> execute(); $SQLnewSignUp->close(); mysqli_close($dbHandle); print(';Congratulations ';.$username.'; you have been signed up! </br>';); } } else { print(';Please retype your password and try again';); } } } else { $username=';';; $password=';';; $comparePassword=';';; }     ?>   <form name=';userForm'; action=';sqlSafety.php'; method=';POST';> Username: <input type=';text'; name=';username';></Br> Password: <input type=';password'; name=';password';> Repeat Password: <input type=';password'; name=';comparePassword';> <input type=';submit'; name =';SignUp'; value=';Sign Up';> </form>   </body> </html>
avatar Re: Chapter 13 - Displaying data from database
March 22, 2013 09:00AM
I have run into a bit of a snag. I am populating a select box(drop down box) in PHP from a database.

Language: PHP
function selBox(){ conDB(); $sql1 = "SELECT cname FROM course"; $selResult = mysql_query($sql1); echo"<option value = ';default';>Select Course</option>"; $rowNum = 0; while($selRows = mysql_fetch_array($selResult)){ echo"<option value = " . $selRows[0] . ">" . $selRows[0] . "</option>"; } mysql_close(); }

The above function gets called in html like this:

Language: HTML
<select name="delCourse"><?php selBox();?></select>

On the same page I get the value of what was selected in the drop box.

Language: PHP
$Selected = $_POST[';delCourse';]; echo $Selected;

What happens is that I have a lot of courses in the database that populates to the dropbox. The user makes a selection and this would then get put in $Selected to be forwarded to another function.

Problem: Echoing the $Selected gives met a double answer like ScienceScience or MathematicsMathematics. I can maybe do some string manipulation on this to get the right answer. Is there another way of getting only a single answer back from what was selected in the dropbox?
Re: Chapter 13 - Displaying data from database
March 22, 2013 09:23AM
Hi Alex.
I don't know if this is the only problem but you are missing a '' before the option closing bracket :

Language: PHP
echo"<option value = " . $selRows[0] . ">" . $selRows[0] . "</option>";
avatar Re: Chapter 13 - Displaying data from database
March 22, 2013 09:49AM
OOPS!!! Miss coppied that one!! I edited it now. Thx!! But the problem remains.


77920317_Colgate Wrote:
-------------------------------------------------------
> Hi Alex.
> I don't know if this is the only problem but you
> are missing a '' before the option closing bracket
> :
>
>
Language: PHP
> echo"<option value = " . $selRows[0] . ">" . > $selRows[0] . "</option>"; >
Re: Chapter 13 - Displaying data from database
March 22, 2013 12:00PM
Hi Alex

I have been looking at your code.
I keep thinking it has to have something to do with effectivly echoing the function:
Language: PHP
$Selected = $_POST[';delCourse';]; echo $Selected;
While the function already gets called and excecuted in html:
Language: PHP
<select name="delCourse"><?php selBox();?></select>

Please post the problem if you find it.
Would also like to know what went wrong.
avatar Re: Chapter 13 - Displaying data from database
March 22, 2013 12:48PM
Not sure. I tried changing the select box name and even using another field in the database for the values of the select box, like:

Language: PHP
function selBox(){ conDB(); $sql1 = "SELECT cid, cname FROM course"; $selResult = mysql_query($sql1); echo"<option value = ';default';>Select Course</option>"; while($selRows = mysql_fetch_array($selResult)){ echo"<option value = " . $selRows[0] . ">" . $selRows[1] . "</option>"; // I think the error may be here?? } mysql_close(); }

The above code still gives me double values. Like 11, 55 or 1010 al depending on the cid value from the database. I just don't know where it is getting the extra value from.
avatar
Mac
Re: Chapter 13 - Displaying data from database
March 22, 2013 01:00PM
What is the select name - delCourse?

Language: PHP
echo "option value=\"".$row[';name_of_column';]."\">".$row["name_of_column"]."</option>"; //why are you using 0??

For a single option, assuming you want to delete a single course, having presented options in a drop down, you simply need something similar to this.

Language: PHP
$result = mysql_query("select id,city from countries"); echo ';<select name="city"><OPTION>';; echo "Select an option</OPTION>"; while ($row = mysql_fetch_array($result)){ $id = $row["id"]; $city = $row["cities"]; echo "<OPTION value=\"$id\">$city</OPTION>"; } echo ';</SELECT>';;

You want to catch just one option, the id in particular, which you send on to a function that deletes the course of course. In your code, you are trying to us the name to delete - not a good idea.

[
avatar Re: Chapter 13 - Displaying data from database
March 22, 2013 01:37PM
Mac, I am still getting double values. Could it be that the function itself is also sending a value back?

What I have now is on my course_man page:

The html that creates the select box and calls the selBox function to populate it with data.

Language: HTML
<select name="delCourse"><?php selBox();?></select>

The function that populates the selectbox (This is in my functions.php file):
Language: PHP
function selBox(){ conDB(); $sql1 = "SELECT cid, cname FROM course"; $selResult = mysql_query($sql1); echo"<option value = ';default';>Select Course</option>"; while($selRows = mysql_fetch_array($selResult)){ $id = $selRows["cid"] ; $course = $selRows["cname"]; echo "<option value=\"$id\">$course</option>"; } mysql_close(); }

This part is for a switch statement that handles the 3 buttons on the page. It is here that when the user clicks on the delete button that it should get the selected value from the selectbox. :

Language: PHP
case "Delete Course": $Selected = $_POST[';delCourse';]; echo $Selected; break;

This also gives double answers. If put this question on StackOverFlow and somebody suggested that I should change my previous line to this:
Language: PHP
echo"<option value = \"" . htmlspecialchars($selRows[';cid';]) ."\">" . htmlspecialchars($selRows[';cname';]) . "</option>";

Because I am working with dynamic content and this makes it open to XSS exploit. Still double answers with this also.

What does the \ do in this statement?

Language: PHP
echo "<option value=\"$id\">$course</option>";
avatar
Mac
Re: Chapter 13 - Displaying data from database
March 22, 2013 03:00PM
It escapes the use of the double quotes within the echo statement which opens and starts with double quotes

Language: PHP
echo "<option value=';$id';>$course</option>"; //else use single qoutes

Are you sure you do not have duplicate entries in your db??
Re: Chapter 13 - Displaying data from database
March 23, 2013 05:18PM
Created database and Table using PhpMyAdmin. This was not too difficult.

Manipulating the database (select,add database using PHP Code) done.

I still have to do the exercises on manipulating Tables using PHP Code.
avatar Re: Chapter 13 - Displaying data from database
March 25, 2013 01:47PM
Mac, I looked in the database, but there is only one of each item entered there. Now I am getting confused. Still can't catch the bug!! sad smiley


mac Wrote:
-------------------------------------------------------
> It escapes the use of the double quotes within the
> echo statement which opens and starts with double
> quotes
>
>
Language: PHP
> echo "<option value=';$id';>$course</option>"; > //else use single qoutes >
>
> Are you sure you do not have duplicate entries in
> your db??
avatar
Mac
Re: Chapter 13 - Displaying data from database
March 25, 2013 02:42PM
Best way to catch it is to first write a simple query outside a function.
avatar Re: Chapter 13 - Displaying data from database
March 27, 2013 01:07PM
Got my error!!! smiling bouncing smiley WOW!! Just by playing around with the function I happend on to the answer. PHP is a real trickster, but I got it!!!
avatar
Mac
Re: Chapter 13 - Displaying data from database
March 27, 2013 02:26PM
Share it!!!! One truth, no matter your experience, is that you will spend hours to find a bug. Problem is, the more experienced, the more you miss the errors in code you think you have mastered.
Re: Chapter 13 - Displaying data from database
March 27, 2013 02:34PM
Hi.

Just doing a quick refresh on the lessons.:

"mysql_fetch_assoc( )" function. This a associative array function right? Meaning all the values of the specific table that is called is put inside a associative array: [column] => Row value. What if the values in the database is not associative ? What do you do when values that are stored on default [key] values if that is the case ? Will the "mysql_fetch_assoc( )" function assign the current "x" key value to associative layout with the current row ?

Student Number: 78042879 (Part Time Courses)
avatar
Mac
Re: Chapter 13 - Displaying data from database
March 27, 2013 02:57PM
Have a look at this tutorial: http://www.phpf1.com/tutorial/php-array.html

Arrays can be very tricky. It is one of those functions that depends on what you have and what you want to achieve, and somehow even then you have choices. The problem with a tut like the one here above, while explaining the concept nicely, is that it assumes you "hard code" the array options. In general terms, and because arrays are normally caught with a form, just keep in mind that you catch them with a [].... as in name=course[]. Getting them IN is the easy part - getting them OUT is trickier..... so read this tut keeping this in mind.
Re: Chapter 13 - Displaying data from database
March 27, 2013 03:02PM
mac Wrote:
-------------------------------------------------------
> Have a look at this tutorial:
> http://www.phpf1.com/tutorial/php-array.html
>
> Arrays can be very tricky. It is one of those
> functions that depends on what you have and what
> you want to achieve, and somehow even then you
> have choices. The problem with a tut like the one
> here above, while explaining the concept nicely,
> is that it assumes you "hard code" the array
> options. In general terms, and because arrays are
> normally caught with a form, just keep in mind
> that you catch them with a [].... as in
> name=course[]. Getting them IN is the easy part -
> getting them OUT is trickier..... so read this tut
> keeping this in mind.

Thank You Mac.

So basically you need to make sure that your "input" is structured correctly like with a kind of delimiter or enforce rules on the input ?

Tutorial = Thank you for the Info! Multidimensional arrays is something I am going to play with. Arrays looks allot like SETS and SUBSETS in math.

Student Number: 78042879 (Part Time Courses)
avatar Re: Chapter 13 - Displaying data from database
March 27, 2013 04:01PM
This is what I found:

I had this function to populate my select box: (Thank you Mac for the latter part on using the id's rather than the names!!)

Language: PHP
//Shows all the courses in the database in select box function selBox(){ conDB(); $sql1 = "SELECT cid, cname FROM course"; $selResult = mysql_query($sql1); echo"<option value = ';default';>Select Course</option>"; while($selRows = mysql_fetch_array($selResult)){ $id = htmlspecialchars($selRows["cid"]) ; $course = htmlspecialchars($selRows["cname"]); echo "<option value=';$id';>$course</option>"; } mysql_close(); }

My HTML on my page then called this function like this:

Language: HTML
<select name="delCourse"><?php selBox($selValue);?></select>

On the same page I have 3 buttons that was handled by a switch statement, to see what button was clicked. This is where the code went haywire and gave me double values.

Language: PHP
case "Delete Course": $Selected = $_POST(';delcourse';); //delcourse is the name of my selectbox echo $Selected; break;

In practice there is nothing wrong with this code, BUT at the top of my switch block I had this:

Language: PHP
if (isset($_POST[';delCourse';])) { $Selected = ($_POST[';delCourse';]); print_r $Selected; }

I was getting my double values from a print_r and a subsequent echo!! Nearly slapped myself for not picking this up. Best way to catch this was to print out the code on paper and take a pen and work through the lines of code. On screen I missed this by miles!!!
Re: Chapter 13 - Displaying data from database
March 27, 2013 04:14PM
Hi 77843835AlexB.

Look up "Variable Diagrams". I am still looking for a tool or going to write my own if I can't find one.

Something in C++ they forced us learn to find errors is Variable Diagrams.

Example:

Line1: $sum = 0;
Line2: $var1 = 2;
Line3: $var2 = 3;
LIne4:
Line5: $sum = $var1 + $var2;
Line6:

Draw the following on a piece of paper:

............SUM......VAR1......VAR2

Line 1: [ 0 ] [ 0 ] [ 0 ]
Line 2: [ 0 ] [ 2 ] [ 0 ]
Line 3: [ 0 ] [ 2 ] [ 3 ]
Line 4: [ 0 ] [ 2 ] [ 3 ]
Line 5: [ 5 ] [ 2 ] [ 3 ]

Student Number: 78042879 (Part Time Courses)
Sorry, only registered users may post in this forum.

Click here to login