url link instead of submit button

i’m doing a list of books from a database. on the while statement using submit button, variable data from action post to page works fine, getting the desired value of the form, but when i change the submit button to url link, the data sent to page was always the last value of the variable. any workaround to make the url link work? thanks
here’s the submit button code
[php]

<?php $library = generalbooks; require_once("db/db.php"); $db = new libraryDb; $result = $db->show_categories($library ); print ''; echo ''; while ($callnumber = mysql_fetch_array($result)){ $cn = $callnumber["CallNumber"]; echo '"; $referencenumberdb = mysql_query("SELECT * FROM ".$library. " WHERE CallNumber = '".$cn."' GROUP BY ReferenceNumber ORDER BY CallNumber, ReferenceNumber"); while ($referencenumber = mysql_fetch_array($referencenumberdb)){ $rn = $referencenumber["ReferenceNumber"]; echo ''; ?>
<td>
<form name="myform" action="categoryBl.php" method="post">  		
<input type="hidden" name="category" value="<?php echo $cn; ?>"/>
<input type="hidden" name="subcategory" value="<?php echo $rn; ?>"/>
<input type="submit" name="viewreport" value="<?php echo $rn; ?>"/>
</form>	</td>	<?php
$numbooks = mysql_num_rows(mysql_query("SELECT * FROM ".$library. " WHERE CallNumber = '".$cn."' AND ReferenceNumber = '" . $referencenumber["ReferenceNumber"]. "'  ORDER BY CallNumber, ReferenceNumber"));
echo '<td align="center">'.$numbooks."</td>";	
print"</tr>"; 
	}			
}
print "</table>";

?>[/php]

heres the url code
[php]

<?php $library = generalbooks; require_once("db/db.php"); $db = new libraryDb; $result = $db->show_categories($library ); print '
Categories No. of Books
' . $cn."
-
'; echo ''; while ($callnumber = mysql_fetch_array($result)){ $cn = $callnumber["CallNumber"]; echo '"; $referencenumberdb = mysql_query("SELECT * FROM ".$library. " WHERE CallNumber = '".$cn."' GROUP BY ReferenceNumber ORDER BY CallNumber, ReferenceNumber"); while ($referencenumber = mysql_fetch_array($referencenumberdb)){ $rn = $referencenumber["ReferenceNumber"]; echo '"; $numbooks = mysql_num_rows(mysql_query("SELECT * FROM ".$library. " WHERE CallNumber = '".$cn."' AND ReferenceNumber = '" . $referencenumber["ReferenceNumber"]. "' ORDER BY CallNumber, ReferenceNumber")); ?> <?php echo '"; print""; } } print "
Categories No. of Books
' . $cn."
- ' . $referencenumber["ReferenceNumber"]."'.$numbooks."
"; ?>[/php]

Well, first, a URL link has nothing to do with a FORM. Form’s are POSTED, not redirected by a URL link.
Why change a working FORM into a link. Link’s can not pass data unless you use them with arguments something like: www.xyz.com/index.php?argument1=1, arg2=939,etc= …

Not sure what you are attempting to do by removing the form and inserting a link? What are you trying to accomplish? Perhaps a little more info and we can solve it for you.

But, in case you really wanted it that way, you are calling a Javascript to post your form from a link. A backwards way to to it. And, you are using the same calling script to use this Javascipt. It other words, you are calling the same script with no arguments. If you want something passed to the submit in the Javascript, you can do this by passing it inside the call.
Instead of =submitform() use =submitform(this.value) and in the function submitform(value) and
use the value for whatever. Submitting from the same link will just pass the last value not the one that
is attached to the link.
Still do not understand why this would be useful… Perhaps you are planning some validation that you have not discussed… Anyway, hope this helps…

thanks a lot. I made it work now.
I did a javascripts function dynamically creating a form getting the value from the array.

What im trying to accomplish here is that i list all the subcategories sorted by category.
When I click the subcategory, it will go to another page listing all the books within that subcategory.
the problem before is how i get the value of subcategories to make the query.

here is now the working script.

[php]

<?php $library = generalbooks; require_once("db/db.php"); $db = new libraryDb; // get data group by callnumber $result = $db->show_categories($library ); print ''; echo ''; // list by callnumber while ($callnumber = mysql_fetch_array($result)){ $cn = $callnumber["CallNumber"]; echo '"; // get data group by reference number $referencenumberdb = mysql_query("SELECT * FROM ".$library. " WHERE CallNumber = '".$cn."' GROUP BY ReferenceNumber ORDER BY CallNumber, ReferenceNumber"); // // //list by reference number while ($referencenumber = mysql_fetch_array($referencenumberdb)){ $rn = $referencenumber["ReferenceNumber"]; echo '"; // get the number of books by reference number $numbooks = mysql_num_rows(mysql_query("SELECT * FROM ".$library. " WHERE CallNumber = '".$cn."' AND ReferenceNumber = '" . $rn. "' ORDER BY CallNumber, ReferenceNumber")); ?>
 </form>
<?php echo '"; print""; } } print "
Categories No. of Books
' . $cn."
- '; print '' . $rn." '.$numbooks."
"; ?>[/php]

Why didn’t you just use two dropdowns, the first populating the second one? We have lots of sample here on this site and on others…

dropdown is not an option. here’s a view of what the code will output

image located at https://lh5.googleusercontent.com/-hsP9XIXxAFU/T1f6-mQmYkI/AAAAAAAAACQ/ro8Bs_gb8is/s575/library.jpg

onclicking blue text triggers the function to post the value of the text(blue) and the location(top most category) on the next page to list all the books. their values will be used in the query to get all books for that specific field.

Anyway thanks for your reply, it helps alot, everything working now
onclick=post_to_url({‘name1’:‘value1’,‘name2’:‘value2’})

I’m sorry, now I understand what you were doing. Glad you got it to work. That is always a nice feeling…

yes, and thanks to you for the parameter option you mentioned.
now i got it working all fine
here’s the final site, though its still in beta since the database needs to be finished yet.
http://www.freinademetzcenter.org/librarysystem/index.php

Sponsor our Newsletter | Privacy Policy | Terms of Service