Jump to content

wkilc

Members
  • Posts

    130
  • Joined

  • Last visited

Posts posted by wkilc

  1. Hello,

     

    I am trying to capture a full URL, including any variables (queries)

     

    Fro example... if the page that is filtered was...

    "index.php?car=Honda"

     

    I THINK I'm in the ballpark, but I cannot get the syntax right.

     

    <? $page_name =  "index.php?=$_SERVER['QUERY_STRING']"; ?>

     

    Thank you.

     

    ~Wayne

  2. Howdy,

     

    Trying to implement a paging script.

     

    The example shows how to use a "static" page name to create the link "NEXT" and "PREV" links...

     

    $page_name="index.php";
    
    print "<a href='$page_name?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";}

     

    I want to make it so that the page name that appears on the link is dynamic, at any given time, it might be queried like this:

    index.php?category=Toyota

    I tired this, but it didn't work:

    $page_name = $HTTP_SERVER_VARS['PHP_SELF'];

     

    I'm a noob, if it's not obvious. :-[

     

    Thanks in advance.

     

    ~Wayne

  3. In this, why have you quoted " . $row['instrument'] . "

     

    In short... because I'm and idiot.  :-[

     

    Here was the solution:

    if($_GET['instrument'] ==  $row['instrument'] ){ echo "selected=\"selected\""; } 

     

    Thanks very much!

     

    ~Wayne

  4. I am trying to use my very limited knowledge to merge two working scripts.

     

    The short version, this is giving me a syntax error:

    if($_GET['instrument'] == " . $row['instrument'] . "){ echo "selected=\"selected\""; }  

    Error - unexpected T_ENCAPSED_AND_WHITESPACE

     

    More details...

     

    This generates a nice pulldown menu from a database, no duplicate, redundant rows:

     

    <form name="form" action="index.php" method="get">
    $result = @mysql_query("select distinct cars * from mytable");
    if (mysql_num_rows($result) > 0) {
    print "<select name=\"cars\">"; 
    while ($row = mysql_fetch_array($result)) {
    print "<option value=\"" . $row['cars'] . "\">" . $row['cars'] . "</option>\n";
    }
    print "</select>";
    }
    mysql_free_result($result);  
    ?>
    <input type="submit" value="Go">
    </form>

     

    This static menu creates and echo "selected" for the selected value of the menu, so it remains as the selected choice value in the menu:

    <form name="form" action="index.php" method="get">
    <select name="car">
    <option <?php if(empty($_GET['car'])){ echo "selected=\"selected\""; } ?> value="">DISPLAY ALL</option>
    <option <?php if($_GET['car'] == "honda"){ echo "selected=\"selected\""; } ?> value="honda">honda</option>
    <option <?php if($_GET['car'] == "toyota"){ echo "selected=\"selected\""; } ?> value="toyota">toyota</option>
    <option <?php if($_GET['car'] == "ford"){ echo "selected=\"selected\""; } ?> value="ford">ford</option>
    </select>
     <input type="submit" value="Go">
    </form>

     

    I am trying to use the echo select on the first "dynamic" menu:

     

    <form name="form" action="index.php" method="get">
    <?
    $result = @mysql_query("select distinct instrument from bocj ORDER BY instrument ASC");
    if (mysql_num_rows($result) > 0) {
    print "<select name=\"instrument\">"; 
    while ($row = mysql_fetch_array($result)) {
    print "<option ";
    if($_GET['instrument'] == " . $row['instrument'] . "){ echo "selected=\"selected\""; }  
    print " value=\"" . $row['instrument'] . "\">" . $row['instrument'] . "</option>\n";
    }
    print "</select>";
    }
    mysql_free_result($result);  
    ?>
     <input type="submit" value="Go">
    </form>

     

    Thanks once again.

     

    ~Wayne

  5. Now I'm trying to echo "selected" so the menu holds it's current choice value... I'm pretty sure this is where I'm going wrong, syntax error:

    if($_GET['instrument'] == ". $row['instrument'] ."){ echo "selected=\"selected\""; } 

     

    unexpected T_ENCAPSED_AND_WHITESPACE

     

    <form name="form" action="index.php" method="get">
    <?
    
    $result = @mysql_query("select distinct instrument from bocj ORDER BY instrument ASC");
    if (mysql_num_rows($result) > 0) {
      print "<select name=\"instrument\">"; 
      while ($row = mysql_fetch_array($result)) {
        print "<option ";
        if($_GET['instrument'] == ". $row['instrument'] ."){ echo "selected=\"selected\""; }  
        print " value=\"" . $row['instrument'] . "\">" . $row['instrument'] . "</option>\n";
      }
      print "</select>";
    }
    mysql_free_result($result);  
    
    ?>
     <input type="submit" value="Go">
    </form>

     

    ~Wayne

  6. This works....

     

    <form name="form" action="index.php" method="get">
    <?
    
    $result = @mysql_query("select * from mytable");
    if (mysql_num_rows($result) > 0) {
      print "<select name=\"instrument\">"; 
      while ($row = mysql_fetch_array($result)) {
        print "<option value=\"" . $row['instrument'] . "\">" . $row['instrument'] . "</option>\n";
      }
      print "</select>";
    }
    mysql_free_result($result);  
    
    ?>
    <input type="submit" value="Go">
    </form>

     

    But I only want unique rows listed :

    flute

    drum

    guitar

     

    and not:

    flute

    drum

    guitar

    flute

     

    ...and I'd like them in alphabetical order (order by?)

     

    I was reading about "distinct"... figured I change the query from:

    $result = @mysql_query("select * from mytable");

    to:

    $result = @mysql_query("select distinct from mytable");

     

    But that creates an error.

     

    Thank you.

     

    ~Wayne

     

     

  7. index.php will show all records.

     

    I want to query (filter) the database like this:

    index.php?car=toyota

    or

    index.php?car=honda

     

    <form name="form" action="index.php" method="get">
    <b>Filter cars:</b><br>
    <select name="car">
    <option value="">DISPLAY ALL</option>
    <option value="honda">honda</option>
    <option value="toyota">toyota</option>
    <option value="ford">ford</option>
    </select>
     <input type="submit" value="Go">
    </form>

     

    It works just fine... the page is filtered correctly.  The only problem is with every submit, the menu defaults back to the first value "DISPLAY ALL". 

     

    Is there any simple way to make the pulldown menu "hold" the value that it's currently displaying?

     

    Thanks,

     

    ~Wayne

  8. Thanks once again  for the help.  ;D

     

    I've changed my method... it works, but it doesn't.

     

     

    Here's a test page:

    http://www.menc-eastern.org/test.php

     

    You see 5 records.

     

    Now "query" the database:

    http://www.menc-eastern.org/test.php?instrument=Winds-Flute

     

    Just two records, flute ones... so far, so good.

     

    Now click on one of the hyperlinked "ranks"... change the rank number and Update the value.

     

    It displays "Student was successfully updated!"... and it goes back to the URL I wanted

    http://www.menc-eastern.org/test.php?instrument=Winds-Flute

     

    ... but there is only one student listed there (the one that was just updated).  Copy and paste the EXACT same URL in a new tab, and it displays both students.

     

    How do I make it display all (in this case, both) students, immediately after the update?

     

    ~Wayne

     

     

    Here's my latest code:

     

    <? $foobar = getenv('HTTP_REFERER'); ?>
    
    <?
        if (isset($_POST['updatestudentbt']))
    {
    	if ($_POST['rank'] != '')
    	{
    		if (mysql_query("UPDATE bocj SET `rank` = '".$_POST['rank']."' WHERE `id`= '".$_POST['id']."'"))
    			echo "Student was successfully updated!<br /><br />";
    		else
    			echo "Student was NOT updated!<br /><br />";
    	}
    
    }
    
    if ($_GET['a'] == "edit")
        {
    	$sql = "SELECT * FROM bocj WHERE id='".$_GET['id']."'";
        	$result = mysql_query($sql);
        	$data = mysql_fetch_array($result);
    ?>
    
    
        <form action="<? echo $foobar?>" method="post" name="editstudent">
         <b>Name</b>: <? echo $data['student']?>  
    <br />
         <b>Instrument</b>: <?=$data['instrument']?>
            <br />
            <br />
            <b>Rank</b>: <input name="rank" type="text" id="rank" size="7" value="<? echo $data['rank']?>" onfocus="if(this.value=='rank?') {this.value='';}" onblur="if(this.value=='rank?') {this.value='';}" />
            <br />
            <br />
            <input type="hidden" name="id" value="<? echo $data['id']?>" />
            <input type="submit" value="Update" name="updatestudentbt" />
          </p>
      </form>
    <br />
    
    <?
    }
        else
        {
        ?>
    
    
    <?
      function pparams($sort) {
        global $sponsor, $school, $student, $instrument;
    
        echo $HTTP_SERVER_VARS['PHP_SELF'];
        echo "?sponsor=".htmlentities(urlencode($sponsor));
        echo "&student=".htmlentities(urlencode($student));
        echo "&instrument=".htmlentities(urlencode($instrument));
        echo "&sort=".htmlentities(urlencode($sort));
      }
    
      if (!$sort) $sort="instrument";
    ?>
    
    
          	<table>
          	<tr>
            <td><strong><a href="<? pparams("sponsor"); ?>">Sponsor</a></strong></td>
            <td><strong><a href="<? pparams("student"); ?>">Student</a></strong></td>
    <td><strong><a href="<? pparams("instrument"); ?>">Instrument</a></strong></td></td>
    <td><strong><a href="<? pparams("rank"); ?>">Rank</a></strong></td>
    <td><strong>Comments</strong></td>
        	</tr>
           	<?
        	$sql = "SELECT bocj.sponsor,bocj.student,bocj.instrument,bocj.rank,bocj.id,bocj.comments
            FROM bocj
            WHERE ((bocj.sponsor LIKE '$sponsor%')
                  	and (bocj.student LIKE '$student%')
       		and (bocj.instrument LIKE '$instrument%')
       		and (bocj.rank LIKE '$rank%')
       		and (bocj.id LIKE '$id%')
       		and (bocj.comments LIKE '$comments%'))
            ORDER BY bocj.$sort";
        	$result = mysql_query($sql);
            while ($data = mysql_fetch_array($result))
    
        	{
        	?>
        	<tr>
    <td><?=$data['sponsor']?></td>
    <td><?=$data['student']?></td>
    <td><?=$data['instrument']?></td>
    <td><a href="test.php?p=index&a=edit&id=<?=$data['id']?>"><?=$data['rank']?></a></td>
            <td width="120"><?=$data['comments']?></td>
            </tr>
            <?}?>
        </table>
    <? } ?>

  9. Thank you for the replies...

     

    I tried this... doesn't work.

    <form action="history.go(-1)" method="post" name="editstudent">

     

    The form IS on the same page, I believe... I didn't write it.  I'm a newbie, if you haven't guessed. :-[

     

    Here's the complete code, sorry for pasting so much:

     

     

     <?
        if (isset($_POST['updatestudentbt']))
    {
    	if ($_POST['rank'] != '')
    	{
    		if (mysql_query("UPDATE bocj SET `rank` = '".$_POST['rank']."' WHERE `id`= '".$_POST['id']."'"))
    			echo "Student was successfully updated!<br /><br />";
    		else
    			echo "Student was NOT updated!<br /><br />";
    	}
    
    }
    
        if ($_GET['a'] == "cdelete")
        {
    	mysql_query("DELETE FROM bocj WHERE id='".$_GET['id']."'");
    }
    
    
    if ($_GET['a'] == "edit")
        {
    	$sql = "SELECT * FROM bocj WHERE id='".$_GET['id']."'";
        	$result = mysql_query($sql);
        	$data = mysql_fetch_array($result);
    ?>
        <form action="index.php?p=index" method="post" name="editstudent">
         <b>Name</b>: <? echo $data['student']?>  
    <br />
         <b>Instrument</b>: <?=$data['instrument']?>
            <br />
            <br />
            <b>Rank</b>: <input name="rank" type="text" id="rank" size="7" value="<? echo $data['rank']?>" />
            <br />
            <br />
            <input type="hidden" name="id" value="<? echo $data['id']?>" />
            <input type="submit" value="Update" name="updatestudentbt" />
          </p>
      </form>
    <br />
    <a href="index.php?p=index">Go back</a>
    <?
    }
        else
        {
        ?>
    
    
    <?
      function pparams($sort) {
        global $sponsor, $school, $student, $instrument;
    
        echo $HTTP_SERVER_VARS['PHP_SELF'];
        echo "?sponsor=".htmlentities(urlencode($sponsor));
        echo "&student=".htmlentities(urlencode($student));
        echo "&instrument=".htmlentities(urlencode($instrument));
        echo "&sort=".htmlentities(urlencode($sort));
      }
    
      if (!$sort) $sort="instrument";
    ?>
    
    
          	<table>
          	<tr>
            <td><strong><a href="<? pparams("sponsor"); ?>">Sponsor</a></strong></td>
            <td><strong><a href="<? pparams("student"); ?>">Student</a></strong></td>
    <td><strong><a href="<? pparams("instrument"); ?>">Instrument</a></strong></td></td>
    <td><strong><a href="<? pparams("rank"); ?>">Rank</a></strong></td>
        	</tr>
           	<?
        	$sql = "SELECT bocj.sponsor,bocj.student,bocj.instrument,bocj.rank,bocj.id
            FROM bocj
            WHERE ((bocj.sponsor LIKE '$sponsor%')
                  	and (bocj.student LIKE '$student%')
       		and (bocj.instrument LIKE '$instrument%')
       		and (bocj.rank LIKE '$rank%')
       		and (bocj.id LIKE '$id%')
            ORDER BY bocj.$sort";
        	$result = mysql_query($sql);
            while ($data = mysql_fetch_array($result))
    
        	{
        	?>
        	<tr>
    <td><?=$data['sponsor']?></td>
    <td><?=$data['student']?></td>
    <td><?=$data['instrument']?></td>
    <td><a href="index.php?p=index&a=edit&id=<?=$data['id']?>"><?=$data['rank']?></a>
    	</td>
    	</tr>
            <?}?>
        </table>
    <? } ?>
    

     

    ~Wayne

     

     

  10. Hello,

     

    I have a form that allows users to change to particular value in a database.

     

    You can query the page... for example, this URL will display only the student records that are "Flute":

    index.php?instrument=Flute

     

    Here's my question, if folks use the form and update a record, it takes currently them back to "index.php?p=index" after the update...

     

    How can I "trap" the URL they were just looking at, sending them back to the same "queried" page they were just on, showing the same records that were just looking at?  I guess it would be almost like using the "back button".  It would need to be dynamic... it might be "index.php?instrument=Flute", or "index.php?instrument=Violin"

     

    Here's the form code.

     

     

    <form action="index.php?p=index" method="post" name="editstudent">
      <b>Name</b>: Kent, Clark  
    <br />
         <b>Instrument</b>: Winds-Flute 
            <br />
            <b>Rank</b>: <input name="rank" type="text" id="rank" size="7" value="2" />
    
            <br />
            <br />
            <input type="hidden" name="id" value="5" />
            <input type="submit" value="Update" name="updatestudentbt" />
          </p>
      </form>
    <br />
    <a href="index.php?p=index">Go back</a>

     

    TIA for any help,

     

    ~Wayne

     

     

     

  11. Thank you!

     

    The reason was that I need both values passed by the form, one that says the size of the booth WITH the cost, and one with just the numerical cost (for some calculations).

     

    Problem... I tried both scripts, but they both only supply "Cost1"... "Cost2" is still an empty value.

     

    ~Wayne

  12. Hello,

     

    I'm using this script to create a second form value (Cost) that depends on the answer to another form value (Booth).

     

    <head>
    <script type="text/javascript">
    function getIPut(val)
    {
    var state = document.getElementById('Booth1').value;
    var loca;
    if(booth == 'large - $950'){
    	loca = '950';
    }else if(booth == 'medium - $850'){
    	loca = '850';
    }else if(booth == 'small - $750'){
    	loca = '750';
    }
    document.getElementById('Cost1').value = loca;
    }
    </script>
    </head>
    
    Booth type:
    <label>
    <select onchange="getIPut();" id="Booth1" name="Booth1">
    <option value=""></option>
    <option id="booth" value="large - $950">large - $950</option>
    <option id="booth" value="medium - $850">medium - $850</option>
    <option id="booth" value="small - $750">small - $750</option>
    </select>
    </label>
    
    <input id="Cost2" type="hidden" name="Cost1" />

     

    It works fine, until I try to duplicate it (two "Booths" and two "Costs")...  I've tried hard-coding it as well as this:

    <head>
    <script type="text/javascript">
    function getIPut(val)
    {
    for (var i = 1; i <= 2; i++ )
    {
    var state = document.getElementById('Booth'+i).value;
    var loca;
    if(booth == 'large - $950'){
    	loca = '950';
    }else if(booth == 'medium - $850'){
    	loca = '850';
    }else if(booth == 'small - $750'){
    	loca = '750';
    }
    document.getElementById('Cost'+i).value = loca;
    }
    }
    </script>
    </head>
    
    Booth type:
    <label>
    <select onchange="getIPut();" id="Booth1" name="Booth1">
    <option value=""></option>
    <option id="booth" value="large - $950">large - $950</option>
    <option id="booth" value="medium - $850">medium - $850</option>
    <option id="booth" value="small - $750">small - $750</option>
    </select>
    </label>
    
    <input id="Cost2" type="hidden" name="Cost1" />
    
    <p />
    
    Booth type:
    <label>
    <select onchange="getIPut();" id="Booth2" name="Booth2">
    <option value=""></option>
    <option id="booth" value="large - $950">large - $950</option>
    <option id="booth" value="medium - $850">medium - $850</option>
    <option id="booth" value="small - $750">small - $750</option>
    </select>
    </label>
    
    <input id="Cost2" type="hidden" name="Cost2" />

     

    Nothing seems to work... I've tried renaming the "getIPut" events as well, in case they were conflicting.

     

    I've been at this simple chore for hours.

     

    Thanks for reading.

     

    ~Wayne

  13. Thanks for the replies!

     

    I had a freelancer work on the code for me... in the first post I was attempting to simplify it in order to make it easy to look at, perhaps I took out something important. 

     

    It's s simple table (protected by .htaccess) where folks can update one of the table values (rank).  I would like to be able to run a query that would allow me to display on records of a particular instrument, or a particular sponsor, etc.

     

    Here's the complete code:

     

    <?
        if (isset($_POST['updatestudentbt']))
    {
    	if ($_POST['rank'] != '')
    	{
    		if (mysql_query("UPDATE bocj SET `rank` = '".$_POST['rank']."' WHERE `id`= '".$_POST['id']."'"))
    			echo "Student was successfully updated!<br /><br />";
    		else
    			echo "Student was NOT updated!<br /><br />";
    	}
    
    }
    
    	if ($_GET['a'] == "edit")
        {
    	$sql = "SELECT * FROM bocj WHERE id='".$_GET['id']."'";
        	$result = mysql_query($sql);
        	$data = mysql_fetch_array($result);
    ?>
        <form action="index.php?p=index" method="post" name="editstudent">
           Name: <? echo $data['student']?>  
    <br />
           Instrument: <?=$data['instrument']?>
            <br />
            <br />
           Rank: <input name="rank" type="text" id="rank" size="7" value="<? echo $data['rank']?>" onfocus="if(this.value=='rank?') {this.value='';}" onblur="if(this.value=='rank?') {this.value='';}" />
            <br />
            <br />
            <input type="hidden" name="id" value="<? echo $data['id']?>" />
            <input type="submit" value="Update" name="updatestudentbt" />
          </p>
      </form>
    <br />
    <a href="index.php?p=index">Go back</a>
    <?
    }
        else
        {
        ?>
    
    
    <?
      function pparams($sort) {
        global $sponsor, $school, $student, $instrument;
    
        echo $HTTP_SERVER_VARS['PHP_SELF'];
        echo "?sponsor=".htmlentities(urlencode($sponsor));
        echo "&student=".htmlentities(urlencode($student));
        echo "&instrument=".htmlentities(urlencode($instrument));
        echo "&sort=".htmlentities(urlencode($sort));
      }
    
      if (!$sort) $sort="instrument";
    ?>
    
    
          	<table>
          	<tr>
            <td><strong><a href="<? pparams("sponsor"); ?>">Sponsor</a></strong></td>
            <td><strong><a href="<? pparams("student"); ?>">Student</a></strong></td>
    <td>dth=<strong><a href="<? pparams("instrument"); ?>">Instrument</a></strong></td></td>
    <td><strong><a href="<? pparams("rank"); ?>">Rank</a></strong></td>
    <td width="120"><strong>Comments</strong></td>
        	</tr>
           	<?
          	$sql = "SELECT * FROM bocj
    ORDER BY bocj.$sort";
        	$result = mysql_query($sql);
            while ($data = mysql_fetch_array($result))
        	{
        	?>
        	 	<tr>
    <td><?=$data['sponsor']?></td>
    <td><?=$data['student']?></td>
    <td><?=$data['instrument']?></td>
    <a href="index.php?p=index&a=edit&id=<?=$data['id']?>"><?=$data['rank']?></a>
    	</td>
            <td><?=$data['comments']?></td>
    	</tr>
            <?}?>
        </table>
    <? } ?>

     

    Any ideas?

     

    ~Wayne

  14. Hello,

     

    I have this basic code running on my "index.php" page.  I'm trying to add a feature where I could query the database by adding a simple query to the URL, for example, "index.php?instrument=flute", so it would display only the rows where the instrument is actually a flute.

     

     <?
    $sql = "SELECT * FROM bocj WHERE id='".$_GET['id']."'";
        	$result = mysql_query($sql);
        	$data = mysql_fetch_array($result);
      
    ?>
    
          	<table>
          	<tr>
            <td>Sponsor</td>
            <td>Student</td>
    <td>Instrument</td>
    <td>Rank</td>
    <td>Comments</td>
        	</tr>
           	
    <?
          	$sql = "SELECT * FROM bocj
    ORDER BY bocj.$sort";
        	$result = mysql_query($sql);
            while ($data = mysql_fetch_array($result))
        	{
    ?>
        	<tr>
    <td><?=$data['sponsor']?></td>
    <td><?=$data['student']?></td>
    <td><?=$data['instrument']?></td>
    <td><?=$data['rank']?></td>
            <td><?=$data['comments']?></td>
    </tr>
            <?  
    }  
    ?>
            </table>
    

     

    I'm a noob, and I've tried many things from many online tutorials, all without much success.

     

    Thanks.

     

    ~Wayne

  15. Thank you...

     

    now no matter what I do, I get thirteen copies of each row from the table.  (There are 13 rows in the table, but I'm getting 13x 13)

     

    <?
    $page_name="index.php"; //  If you use this code with a different page ( or file ) name then change this
    
    @$column_name=$_GET['column_name']; // Read the column name from query string.
    
    ////// starting of drop down to select number of records per page /////
    
    @$limit=$_GET['limit']; // Read the limit value from query string.
    
    $start=$_GET['start'];								// To take care global variable if OFF
    if(!($start > 0)) {                         // This variable is set to zero for the first page
    $start = 0;
    }
    
    $eu = ($start - 0);
    $limit = 10;                                 // No of records to be shown per page.
    $this1 = $eu + $limit;
    $back = $eu - $limit;
    $next = $eu + $limit;
    
    /////////////// WE have to find out the number of records in our table. We will use this to break the pages///////
    $query12=" SELECT * FROM bocj  ";
    $result2=mysql_query($query12);
    echo mysql_error();
    $nume=mysql_num_rows($result2);
    /////// The variable nume above will store the total number of records in the table////
    
    
    /////////// Now let us print the table headers ////////////////
    $bgcolor="#f1f1f1";
    echo "<table width=710 align=left cellpadding=0 cellspacing=0> <tr>";
    echo "<td  bgcolor='dfdfdf' > <font face='arial,verdana,helvetica' color='#000000' size='4'><a href='$page_name?column_name=sponsor'>Sponsor</a></font></td>";
    echo "<td  bgcolor='dfdfdf' > <font face='arial,verdana,helvetica' color='#000000' size='4'><a href='$page_name?column_name=student'>Student</a></font></td>";
    echo "<td  bgcolor='dfdfdf' > <font face='arial,verdana,helvetica' color='#000000' size='4'><a href='$page_name?column_name=instrument'>Instrument</a></font></td>";
    echo "<td  bgcolor='dfdfdf'> <font face='arial,verdana,helvetica' color='#000000' size='4'>Rank</font></td></tr>";
    echo "<td  bgcolor='dfdfdf'> <font face='arial,verdana,helvetica' color='#000000' size='4'> </font></td></tr>";
    
    
    ////////////// Now let us start executing the query with variables $eu and $limit  set at the top of the page///////////
    $query1=" SELECT * FROM bocj  ";
    
    if(isset($column_name) and strlen($column_name)>0){
    $query1 = $query1. " order by $column_name";
    }
    $query1 = $query1. " limit $eu, $limit ";
    $result1 = mysql_query($query1);
    echo mysql_error();
    
    
    //////////////// Now we will display the returned records in side the rows of the table/////////
    
    while($noticia = mysql_fetch_array($result1 ))
    {
    if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';}
    else{$bgcolor='#f1f1f1';}
    
    $sql = "SELECT * FROM bocj";
        	$result = mysql_query($sql);
            while ($data = mysql_fetch_array($result ))
    
       	{
    
    
    echo "<tr >";
    echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>$noticia[sponsor]</font></td>";
    echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>$noticia[student]</font></td>";
    echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>$noticia[instrument]</font></td>";
    echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>$noticia[rank]</font></td>";
    echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'><a href='index.php?p=index&a=edit&id=".$data['id']."'>edit</a><font></td>";
    
    	//  This is the unused delete feature
    	//   if ($_GET['a'] == "delete" AND $_GET['id'] == $data['id'])
    	//   {
            //	echo " (<a href='index.php?p=index'>No</a> - <a href='index.php?p=index&a=cdelete&id=".$data['id']."'>Yes</a>) ";
    	//   }
    	//   else
    	//  echo "<a href='index.php?p=index&a=delete&id=".$data['id']."'>delete</a>";
    
    echo "</tr>";
    }
    }
    echo "</table>";
    
    /////////////// Start the buttom links with Prev and next link with page numbers /////////////////
    echo "<table align = 'left' width='50%'><tr><td  align='left' width='30%'>";
    //// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
    if($back >=0) {
    print "<a href='$page_name?start=$back&column_name=$column_name'><font face='Verdana' size='2'>PREV</font></a>";
    }
    
    //////////////// Let us display the page links at  center. We will not display the current page as a link ///////////
    echo "</td><td align=left width='30%'>";
    $i=0;
    $l=1;
    for($i=0;$i < $nume;$i=$i+$limit){
    if($i <> $eu){
    echo " <a href='$page_name?start=$i&column_name=$column_name'><font face='Verdana' size='2'>$l</font></a> ";
    }
    else { echo "<font face='Verdana' size='4' color=red>$l</font>";}        /// Current page is not displayed as link and given font color red
    $l=$l+1;
    }
    
    
    echo "</td><td  align='right' width='30%'>";
    ///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
    if($this1 < $nume) {
    print "<a href='$page_name?start=$next&column_name=$column_name'><font face='Verdana' size='2'>NEXT</font></a>";}
    echo "</td></tr></table>";
    
    ?>
    
    
    <?
        if (isset($_POST['updatestudentbt']))
    {
    	if ($_POST['rank'] != '')
    	{
    		if (mysql_query("UPDATE bocj SET `rank` = '".$_POST['rank']."' WHERE `id`= '".$_POST['id']."'"))
    			echo "Student was successfully updated!<br /><br />";
    		else
    			echo "Student was NOT updated!<br /><br />";
    	}
    
    }
    
        if ($_GET['a'] == "cdelete")
        {
    	mysql_query("DELETE FROM bocj WHERE id='".$_GET['id']."'");
    }
    
    
    if ($_GET['a'] == "edit")
        {
    	$sql = "SELECT * FROM bocj WHERE id='".$_GET['id']."'";
        	$result = mysql_query($sql);
        	$data = mysql_fetch_array($result);
    ?>
        <form action="index.php?p=index" method="post" name="editstudent">
         Name
     <? echo $data['student']?>
          <p>Rank<br>
            <input name="rank" type="text" id="rank" value="<? echo $data['rank']?>">
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <input type="hidden" name="id" value="<? echo $data['id']?>">
            <input type="submit" value="Update" name="updatestudentbt">
          </p>
      </form>
    <br />
    <a href="index.php?p=index">Go back</a>
    <?
    }
        else
        {
        ?>
    
     
    <? } ?>

     

    I'm sorry to paste so much code... but I've been at this for 8 hours and I'm losing my mind.

     

    ~Wayne

  16. Hello,

     

    I'm a noob... trying to put together two existing scripts...  one looks for a hidden value ($data) needed for updating a value in a MySQL row, the other is a tutorial I found online that allows "paging" and "sorting" of LONG tables.  They both use a "while" statement, fetch array... and it seems they both can't function at the same time.  Removing one makes the other one function.  Is there an easy way around this?

     

    while($noticia = mysql_fetch_array($result))
    
    {
    if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';}
    else{$bgcolor='#f1f1f1';}
    
      	$sql = "SELECT * FROM bocj";
        	$result = mysql_query($sql);
            while ($data = mysql_fetch_array($result))
    
        	{
    
    echo "<tr >";
    echo "<td align=left bgcolor=$bgcolor id='title'>$noticia[sponsor]</td>"; 
    echo "<td align=left bgcolor=$bgcolor id='title'>$noticia[student]</td>"; 
    echo "<td align=left bgcolor=$bgcolor id='title'>$noticia[rank]</td>"; 
    echo "<td align=left bgcolor=$bgcolor id='title'><a href='index.php?p=index&a=edit&id=".$data['id']."'>edit</a></td>";

     

    Thanks.

     

    ~Wayne

  17. Thank you! 

     

    I am embarrassed that I missed the form name... that I should have known.

     

    I think I understand what you mean about a user ID, so it knows which student the rank applies to... if it were a "static" HTML form, I guess I called them "student1", "rank1", "student2", "rank2", etc...

     

    But because the table is generated by the number of students in the MySQL table, I'm not sure (okay, I have no idea) how to do that.

     

    This is what the include "form" script looks like now:

     

    <?php
    
    $rank = $_POST['rank'];
    
    mysql_connect("localhost:/tmp/mysql5.sock", 'username, '********'); mysql_select_db("db_name");
    
    foreach($_POST['rank'] as $rank){
    $query="INSERT INTO db_table (rank) VALUES ('$rank')";
    $res = @mysql_query($query);
    if(!$res){
    echo "Could not insert Rank $rank<br>SQL Error: ".mysql_error()."\n";
    }
    }
    
    mysql_query($query) or die ('Error updating database');
    
    echo "Database updated";
    
    ?>

     

    I hate to post this much code... but just in case the complete code on the form page if it is needed:

     

    <strong>President's Stuff</strong>
    <br/>
    
    <?
      function pparams($sort) {
        global $state_aff, $sponsor, $school, $student, $instrument, $rank, $comments;
    
        echo $HTTP_SERVER_VARS['PHP_SELF'];
        echo "?state_aff=".htmlentities(urlencode($state_aff));
        echo "&sponsor=".htmlentities(urlencode($sponsor));
        echo "&school=".htmlentities(urlencode($school));
        echo "&student=".htmlentities(urlencode($student));
        echo "&instrument=".htmlentities(urlencode($instrument));
        echo "&rank=".htmlentities(urlencode($rank));
        echo "&comments=".htmlentities(urlencode($comments));
        echo "&sort=".htmlentities(urlencode($sort));
      }
    
      if (!$sort) $sort="sponsor";
    ?>
    
    <form method="post" action="../php_includes/update_db.php">
    
    <br>
    <font size="1">Click on any category below to re-sort the list:
    <table border="1" cellspacing="0" cellpadding="2" width="710">
    <tr>
    <td><b><a href="<? pparams("state_aff"); ?>">State MEA</a></b></td>
    <td><b><a href="<? pparams("sponsor"); ?>">Sponsor</a></b></td>
    <td><b><a href="<? pparams("school"); ?>">School</a></b></td>
    <td><b><a href="<? pparams("student"); ?>">Student</a></b></td>
    <td><b><a href="<? pparams("instrument"); ?>">Instrument</a></b></td>
    <td><b><a href="<? pparams("rank"); ?>">Rank</a></b></td>
    <td><b><a href="<? pparams("comments"); ?>">Comments</a></b></td></tr>
    
    <? include("../includes/connect_db_name.inc.php");   ?> 
    
    <? $query =
            "SELECT db_table.state_aff,db_table.sponsor,db_table.school,db_table.student,db_table.instrument,db_table.rank,db_table.comments
            FROM db_table
            WHERE ((db_table.state_aff LIKE '$state_aff%')
          and (db_table.sponsor LIKE '$sponsor%')
                  and (db_table.school LIKE '$school%')
                  and (db_table.student LIKE '$student%')
       and (db_table.instrument LIKE '$instrument%')
       and (db_table.instrument LIKE '$instrument%')
       and (db_table.rank LIKE '$rank%')
       and (db_table.comments LIKE '$comments%'))
            ORDER BY db_table.$sort";
    $resultt = mysql_query($query);
    
    // Determine the number of students
    $number = mysql_num_rows($resultt);
    
    if ($number == 0) {
       print "<strong>Sorry, there were no records matching those criteria</strong>;
    } else {
    while ($row = mysql_fetch_object($resultt)) {
        $state_aff=$row->state_aff;
        $sponsor=$row->sponsor;
        $school=$row->school;
        $student=$row->student;
        $instrument=$row->instrument;
        $rank=$row->rank;
        $comments=$row->comments;
    
    
    print "<tr><td>$state_aff</td>
    <td>$sponsor</td>
    <td>$school</td>
    <td>$student</td>
    <td>$instrument</td>
    <td><input type='text' name='rank[]' size='6' value='$rank'></td>
    <td>$comments</td></tr>";
       }
    }
    
    // Close the databaas connection
    mysql_close();
    
    ?>
    
    </table>
    
    <br />
    <input type="submit" value="Update!" />
    </form>

     

    Thanks again.

     

    ~Wayne

  18. Hello all,

     

    I'm pretty good with HTML, but am still learning PHP... so I may sound kinda ignorant here.  Apologies in advance. :-[

     

    I'm creating a relatively simple PHP page that displays data from a MySQL database (this I've done before)... the data will be presented in a "sort-able" table, with each cell filled with info from the database.  One column in this table will have no info, just empty text fields... folks will use their web browser to fill in values into this empty column and then click a button (below the table) to re-save the new values to the MySQL database.

     

    Here's the page:

    http://menc-eastern.org/test/

     

    Here's the code from the PHP include that is supposed to update the database:

     

    <?php
    
    $rank = $_POST['rank'];
    
    mysql_connect("localhost:/tmp/mysql5.sock", 'username', '**********'); mysql_select_db("database_name");
    
    $query="INSERT INTO database_table (rank) VALUES ('".$rank."')";
    
    mysql_query($query) or die ('Error updating database');
    
    echo "Database updated";
    
    ?>

     

    I "pieced" together that code from some tutorials, as I didn't know what exactly what to do.  If you click the "Update!" button below the table, it appears like it works, but no values are stored.

     

    The other thing that is a problem... is that if you enter a value into one of the "Rank" text fields on the form, and then re-sort the table, the values are lost, they all become blank again.

     

    Thanks for reading.

     

    ~Wayne

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.