Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
|
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 15th, 2004, 01:59 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

I dont think you need <FORM> in while loop. It puts a form for each rows of your recordset, which doesn't seem to be good way of approach. Also, I wonder how many submit buttons would you get there? On click of any of those submit buttons, what is the value that is posted to show.php, where you try to fetch "CODE" value. I dont see value of CODE being substituted in the previous page in your code.

If I am not wrong, I assume that you are trying to show some rows as hyperlink and on click of any of those rows, would take you to show.php where you show the details of that particular row.

For this, I would suggest you to go this way.

1) In while loop remove the FORM tag and SUBMIT button.
2) Just use hyperlink <A> tag and show the rows in the way you want. The hyperlink should have "SHOW.PHP?Code=".$CODE , whatever you wish to pass for each record. Probably the CODE field's value of corresponding record.
3) When clicked on any of the hyperlink in first page, takes you to show.php where you fetch "CODE" value and use that in your SELECT statement to fetch that row alone.

What is the datatype of CODE COLUMN in your table. (ie: $c in this case.) So that I would be able to help you out.

SELECT Code FROM AddTable2 WHERE Code=" . $c

Cheers!


-Vijay G
 
Old April 15th, 2004, 02:16 PM
Authorized User
 
Join Date: Apr 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

First of all I like to thank you for responding to my plea.
ok the datatype for Code is Text. My mentor told me that that is the way you have a field with unlimited space. Anyway, I'm going to take your advice on the form issue. However, according to my mentor and my teacher (who helps me out time to time), the real problem is that the browser is not recognizing the variable that is declared as a field to make that value that is going to database connect with the page (hope you understand what I'm getting at).

 
Old April 15th, 2004, 02:54 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

CODE of First page.

<?php
require_once ('mysql_connect.php'); // connecting to database.

// Im making the query.
$query = "SELECT CONCAT(Id) AS Id, (Name) AS Name, (Description) AS Des, DATE_FORMAT(Date, '%M %d, %Y') AS dr FROM AddTable1 WHERE Description IS NOT NULL ORDER BY Date ASC";
$result = @mysql_query ($query) OR die; // Run the query.
$num = mysql_num_rows ($result); // How many codes are there?

if ($num >0)
{ // If it ran ok

    // Display numbers
    echo "<p><big><b>These are the current number of entries: $num</b></big></p>";



    // Display headers
    echo '<table align="center" border="2" cellspacing="2" cellpadding="2">';
    echo '<tr>';
             echo '<td align="left"><b>Id</b></td>';
             echo '<td align="left"><b>Name</b></td>';
             echo '<td align="left"><b>Category</b></td>';
             echo '<td align="left"><b>Date</b></td>';
             echo '<td></td>';
             echo '<td align="left"><b>Click edit to update</b>';
             echo '<td align="left"><b>Show the table</b></td></td>';
         echo '</tr>';

    // Fetch the data
    while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
        echo "<tr>";
         echo "<td align=\"left\">".stripslashes($row[0])."</td>";
         echo "<td>$row[1]</td>";
         echo "<td align=\"left\"><a href='edit.php?=".edit."'>$row[2]</a></td>";
         echo "<td align=\"left\">$row[3]</td>";
         echo "<td align=\"left\"><a href='edit.php?=".edit."'>$row[4]</a></td>";
         echo "<td><a href='edit.php?=".edit."'>".edit."</a> <br></td>";
         echo "</tr>\n";
}

        echo '</table>';
        mysql_free_result ($result); // free up resources.

        } else { // If it didnt run OK.
            echo
            '<p>there are no codes in this query</p><p>' .mysql_error() . '</p>';
            }
mysql_close(); // Close the database.


include ('WSfooter.inc'); // footer included.
?>

___________________________________

CODE of Show.php

<?php
// This page is to get the sql query to show the table being selected
// The title and header
$page_title = 'Show information';
include ('WSheader.inc');

// Variable Declaration with if statement

$c = $_Get['Code'];



// Query time - for selection of data
require_once ('mysql_connect.php'); // I am making a connection to database

// Variable Declaration with if statement

// This query should show the data from agenda section
$result = mysql_query("SELECT Code FROM AddTable2 WHERE Code='" . $c . "'");

if (!$result) {
    die ("<p>Error performing query: " . mysql_error() . "</p>");
}
else {
    echo ('<p>Your password is: '.$result.'.</p><p>Your password is case sensitive. Make sure you enter it correctly.</p>');
}

mysql_close(); // Close the database.

include ('WSfooter.inc'); //Showing footer

?>

As you said DATATYPE of CODE column is Text type, in select statement, is should be enclosed within quotes as I have made changes in the above code.

Please always follow INDENTING of your code. This will always make you code readble and would be easier to anyone to debug incase of error. Else if would be a pain to go through the code, and anyone for that matter would hesitate to debug that.

The doubt I have here is what does "edit" mean in your first page code? I dont think that is meaningfull, coz, for me it doesnt look like a variable. The hyperlinks in your first page should be something like

href="show.php?Code=". $Code

This should be fetched in show.php as I assume.

I am not sure what your select statement do in the first page. May be you can explain the flow between these 2 pages more in detail. That would help me understand what you are trying to do.

Cheers!


-Vijay G
 
Old April 15th, 2004, 03:24 PM
Authorized User
 
Join Date: Apr 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yeah, man my syntax grammer is almost as worst as my english grammer. You have to excuse me because I just started programming like at the begining of the semester. I concider myself quite good at it but I have beginner syndrom, if you know what I mean. Anyway, the purpose of the edit button is to edit the form I programming (did I mention that this is a FORM!?). Ya see, I have this other page that I'm going to work on to actually up date the data once I finish with this.
The select statement in the first form is to all the first layer of information is surpose to display all of the categories that are surpose to be made by user input. I've manage to have the user in put various data. However, I need the data to be displayed in a certain order. When the user decides to look for a specific data she first comes to the agenda portion of the form (veiwed by the select statement and the while statement). When this happens, she sees a list of categories made by the user when she inputed the data (which I have manage to make work). When the user decides which category she wants, she would click on that row (hyperlink in my case) and see subcategories that is in the main category. From this, she could either edit the data or view it. This is why the purpose of the select statement on the first page. I'm in the process right now of testing it and trying to get it to work.

 
Old April 15th, 2004, 03:35 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:(did I mention that this is a FORM!?).
You dont have to mention that it is a FORM!.

Then why should you put <FORM> tag in your while loop, seeing which anyone could know that it is a form that you are trying to put in while loop. I wanted to know what is the relation between the two tables, AddTable1 and AddTable2. What is the common key that you have in them?

-Vijay G
 
Old April 15th, 2004, 03:51 PM
Authorized User
 
Join Date: Apr 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey, sorry if it sounded like I was getting smart when I said that it was a form. I knew you knew that it was but I wasn't sure. So forgive if you thought I was getting smart because I appreciate the help.

AddTable1 and AddTable2 are levels of data I actually have three tables. AddTable1 is the first table that will be display when the user see that data in the database. AddTable1 purpose is to display all of the categories. Idealy it was surpose to link with a join to AddTable2 which show a more detail version of AddTable1. However, when you click on a certain row on AddTable1, it will only display the related but more detailed information in AddTable2 (I hope that makes sense). However, right now I'm just trying to get it to show data from AddTable2, the joins can come later.

I've tried to do the hyperlink variable technique, and I'm not doing something right. Here's the syntax.

echo "<tr><td align=\"left\">".stripslashes($row[0])."</td><td>$row[1]</td><td align=\"left\"><a href='Show.php?=".Show."'>$row[2]</a></td><td align=\"left\">$row[3]</td><td align=\"left\"><a href='Show.php?=".Show."'>$row[4]</a></td><td><a href='edit.php?=".edit."'>".edit."</a><br></td></tr>\n";
I know that you told me to fix the syntax but I'm still working on fixing it to be presentable and have it work the way I want it too.
You can find the problem where ahref='Show.php?=".Show."'>$row....

Thanks man & God Bless

 
Old April 15th, 2004, 03:57 PM
Authorized User
 
Join Date: Apr 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Additionally, when I click on the hyperlink-
"Your password is: Resource id #5.

Your password is case sensitive. Make sure you enter it correctly."-displays what should I do about that.


 
Old April 15th, 2004, 04:11 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thats fine, No Problem.

Do you get any error at that point?

Quote:
quote:You can find the problem where ahref='Show.php?=".Show."'>$row....
I am really getting confused...

Quote:
quote:echo "<tr><td align=\"left\">".stripslashes($row[0])."</td><td>$row[1]</td><td align=\"left\"><a href='Show.php?=".Show."'>$row[2]</a></td><td align=\"left\">$row[3]</td><td align=\"left\"><a href='Show.php?=".Show."'>$row[4]</a></td><td><a href='edit.php?=".edit."'>".edit."</a><br></td></tr>\n";
In the above code, what does ?=".Show." and ?=".edit." mean?

Also I dont use passing querystrings as you have done.

It should be in this format.
href="xyz.php?StringName=StringValue&CodeName=code Value"

I am not sure if that is possible as you have done, Though it is posible to send as you do there, What does "Show" and "edit" mean, does that mean they are variables?

Also post your table structure. I would always suggest you to give your tables meaningfull name, which would define what data it contains.

Cheers!

-Vijay G
 
Old April 15th, 2004, 04:38 PM
Authorized User
 
Join Date: Apr 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In my form, I have different files that are php files. Right now the ones that I have shown you are:
1) CodeIndex.php which is the longest of all the codes. It is the code you got on me using those submit buttons. Here is the table for that page which the select query queries in AddTable1:
 <center>When you select (or click) these rows, for ex Id field 18 (which would be a hyperlink) it shows all the rows related to Id 18 in AddTable2.</center>
fields id Description Name Code Date
       13 please start at one Alex here you are 20040406130224
       14 nono alex wanna be startin somethin 20040406130708
       15 ccc aaa vvv 20040406130857
       16 pp ppp kkkkk 20040406131155
       17 yyy uuuu yyyyy 20040406131342
       18 I'm adding a very long code alex We 1st connect to our database.
Now, i implemente... 20040406131513
      20 Saying something Alex Something said 20040406133713
      21 Experiment Alex $c 20040409110437
      23 Alex Experiment 20040409110437
It may look alittle funny because I've been inputing test data

2) Show.php is another file. This file contains the next level of information to be view. I will adjust this later but for now I just want related rows to display when I click on one of the rows in CodeIndex page. This significance of the query is to query those rows that are to be selected in the CodeIndex page:

fields Id Description Name Code Date
       13 please start at one Alex here you are 20040406130224
       14 nono alex wanna be startin somethin 20040406130708
       15 ccc aaa vvv 20040406130857
       16 pp ppp kkkkk 20040406131155
       17 yyy uuuu yyyyy 20040406131342
       18 I'm adding a very long code alex We 1st connect to our database.
Now, i implemente... 20040406131513
      20 Saying something Alex Something said 20040406133713
      21 Experiment Alex $c 20040409110437

I hope this helps you understand.


 
Old April 15th, 2004, 04:41 PM
Authorized User
 
Join Date: Apr 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Also edit is a page too. But, don't worry about edit because that's just a page that the edit hyperlink in surpose to goto to make changes to the information in the data base.






Similar Threads
Thread Thread Starter Forum Replies Last Post
SELECT VARIABLE Number of columns drani Oracle 4 September 21st, 2008 01:12 AM
passing javascript variable in xsl:value-of select eruditionist XSLT 2 September 19th, 2008 05:23 PM
Using variable as fieldname in SELECT statement elygp SQL Server 2000 3 April 26th, 2007 10:14 AM
Using a Variable in Select Into anubhav.kumar SQL Server 2000 2 May 26th, 2005 11:02 AM
Setting a variable using Select Case Adam ASP.NET 1.0 and 1.1 Basics 2 September 4th, 2004 02:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.