Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,589 members, 7,809,129 topics. Date: Friday, 26 April 2024 at 12:26 AM

Help Your Girl O Programmers In The House! - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Help Your Girl O Programmers In The House! (2030 Views)

10 Greatest Computer Programmers In History / No Programmers In Nairaland (2) (3) (4)

(1) (Reply) (Go Down)

Help Your Girl O Programmers In The House! by silverluci(f): 2:22pm On Sep 04, 2012
while($row = mysql_fetch_assoc($query)){
echo "<th width='200' align='center' ><a href='books.html?cat_id=". $row["cat_id"] . "'<b>". $row["type"] . "
<img src='images/".$row["cat_image"]."' width='200' height='200' /></a>Price: ".$row["price"]."<br /><b> Quantity:</b> <input name= 'qty' size='5'> <br /><a href=''>add to basket</a></th>";



this is the code but i want to change the url from books.html to something else when someone clicks on another category. i am so stucked but i remembered that i've got some faithful brothers (and sisters?).
Please i am counting on you guys
Re: Help Your Girl O Programmers In The House! by silverluci(f): 2:29pm On Sep 04, 2012
webdezzi and co. please am counting on you guys
kiss cry undecided embarassed undecided
Re: Help Your Girl O Programmers In The House! by Bossman(m): 5:39pm On Sep 04, 2012
If I understand correctly, if the user clicks on a different category, that books.html hyperlink should say something else. In essence you want that to be dynamic depending on the users choice?
Re: Help Your Girl O Programmers In The House! by silverluci(f): 7:27pm On Sep 04, 2012
yes bossman. Exactly. And do i hope to achieve that.
Re: Help Your Girl O Programmers In The House! by Chimanet(m): 7:37pm On Sep 04, 2012
Is d $query variable holding d results of ur query? If so jst change d url from books.html 2 whatever url u want shikena! If nt first run ur query with mysqlquery function b4 trying 2 fetch d results iteratively with mysqlfetchassociative function. Hope dis helps
Re: Help Your Girl O Programmers In The House! by Nobody: 8:05pm On Sep 04, 2012
you have to post the whole code, the section you cut out will leave us wondering what the OriginalCoder was thinking.

and since the category id seems to be passed to the page already, are you sure you will still need the book.html to change?
will the varying value of $row["cat_id"] not do that for you automatically?
Re: Help Your Girl O Programmers In The House! by silverluci(f): 11:49am On Sep 05, 2012
<?php
//connect to server
include('config.php');
$sql = "Select * from category";
$query = mysql_query($sql);
?>
<html>
<head>
<title>Shopping Cart</title>
</head>
<body>
<center>
<img src="images/carton cahrt.jpg" />
<br />
<table>
<form>
<tr>
<td width="200"><input type="submit" name="goods" value="Goods For sale" /></td>
<td width="200"><input type="submit" name="basket" value="Basket Content" /></td>
<td width="200"><input type="submit" name="order" value="Order" /></td>
</tr>
</form>
<?php
if($query){
echo "<tr>";
while($row = mysql_fetch_assoc($query)){
echo "<th width='200' align='center' ><a href='books.html?cat_id=". $row["cat_id"] . "'<b>". $row["type"] . "
<img src='images/".$row["cat_image"]."' width='200' height='200' /></a>Price: ".$row["price"]."<br /><b> Quantity:</b> <input name= 'qty' size='5'> <br /><a href=''>add to cart</a></th>";
}
echo "</tr>";
}
?>
</table>
</center>
</body>
</html>

that's all the code. it has three category. the books, the gadgets and phone. each category is a link to each page. the problem is how do i link each of them to their respective page with this code. i am still stuck o to change the bolded to something else
Re: Help Your Girl O Programmers In The House! by megaplaza(m): 5:34pm On Sep 05, 2012
use a variable say $page to hold the page e.g $page = 'book.html' so that use use
href="'".$page.'?cat_id= ...... This will enable you to change page variable dynamically e.g
If($category == value){
$page = 'phone.html';
}....

Sorry am using my fone to reply cant format the codes well but this should give you an idea

1 Like

Re: Help Your Girl O Programmers In The House! by csharpjava(m): 6:54pm On Sep 05, 2012
Try this code below which uses a switch:

<html>
<head>
<title>Shopping Cart</title>
</head>
<body>
<center>
<img src="images/carton cahrt.jpg" />
<br />
<table>
<form>
<tr>
<td width="200"><input type="submit" name="goods" value="Goods For sale" /></td>
<td width="200"><input type="submit" name="basket" value="Basket Content" /></td>
<td width="200"><input type="submit" name="order" value="Order" /></td>
</tr>
</form>
<?php
//connect to server
include('config.php');
$sql = "Select * from category";
$query = mysql_query($sql);
{
echo "<tr>";
while($row = mysql_fetch_assoc($query)){

switch ($query) {
case 'books' :
echo "<th width='200' align='center' ><a href='books.html?cat_id=". $row["cat_id"] . "'<b>". $row["type"] . "
<img src='images/".$row["cat_image"]."' width='200' height='200' /></a>Price: ".$row["price"]."<br /><b> Quantity:</b> <input name= 'qty' size='5'> <br /><a href=''>add to cart</a></th>";
break;

case 'gadgets' :
echo "<th width='200' align='center' ><a href='gadgets.html?cat_id=". $row["cat_id"] . "'<b>". $row["type"] . "
<img src='images/".$row["cat_image"]."' width='200' height='200' /></a>Price: ".$row["price"]."<br /><b> Quantity:</b> <input name= 'qty' size='5'> <br /><a href=''>add to cart</a></th>";
break;

case 'phone' :
echo "<th width='200' align='center' ><a href='phone.html?cat_id=". $row["cat_id"] . "'<b>". $row["type"] . "
<img src='images/".$row["cat_image"]."' width='200' height='200' /></a>Price: ".$row["price"]."<br /><b> Quantity:</b> <input name= 'qty' size='5'> <br /><a href=''>add to cart</a></th>";

break;
default :
// do some error handling here
echo "Please Select a Category";
break;
}
}
echo "</tr>";
}
?>
</table>
</center>
</body>
</html>

1 Like

Re: Help Your Girl O Programmers In The House! by slightlyMad(f): 10:23pm On Sep 05, 2012
what and where will the trigger come from
am referring to the what will tell this code which of the 3 you want to load and where they will come from.

the code provided by csharpjava should help but you will still be as lost you were without integrating that into this
Re: Help Your Girl O Programmers In The House! by okeyxyz(m): 10:51pm On Sep 05, 2012
silverluci:
while($row = mysql_fetch_assoc($query)){
echo "<th width='200' align='center' ><a href='books.html?cat_id=". $row["cat_id"] . "'<b>". $row["type"] . "
<img src='images/".$row["cat_image"]."' width='200' height='200' /></a>Price: ".$row["price"]."<br /><b> Quantity:</b> <input name= 'qty' size='5'> <br /><a href=''>add to basket</a></th>";


@megaplaza has got the best idea for your script.
You are trying to change pages but forgetting that you have made your pages static instead of dynamic, so a variable $pages would help you switch pages between books.html, gadgets.html and phone.html. One possible trigger is to include a "pages" column in your database table so that after you retrieve the row through $row =mysql_fetch_assoc($query); then

$pages =$row['pages'];

@csharpjava's code has a flaw(though the strategy is right) in that he's running a switch statement on $query, forgetting that $query is a rowset and not a variable expression, therefore $query is not resolved before running switch statement. So the solution would still be to resolve $query through mysql_fetch_assoc(), after including "pages" column in your database table.
Re: Help Your Girl O Programmers In The House! by mitey(m): 1:43am On Sep 06, 2012
Since your application is database powered, you can store the names of the pages in a new table row in your database table.
From line 24 of your code.

if($query){
echo "<tr>";
while($row = mysql_fetch_assoc($query)){
echo "<th width='200' align='center' ><a href='".$row["cat_name"].".html?cat_id=". $row["cat_id"]. "'<b>". $row["type"] . "<img src='images/".$row["cat_image"]."' width='200' height='200' /></a>Price: ".$row["price"]."<br /><b> Quantity:</b> <input name= 'qty' size='5'> <br /><a href=''>add to cart</a></th>";
}
echo "</tr>";
}


Here I replaced the static url 'books.html' with one generated from the value in the category name field 'cat_name' of the database table. I assume the available values here will be books, gadgets and phones.

All you now need to do is create some nice pages, (Why not use use .php?) to process your shopping cart.

Hope this helps a little. Cheers.
Re: Help Your Girl O Programmers In The House! by csharpjava(m): 6:06am On Sep 06, 2012
okeyxyz:
@csharpjava's code has a flaw(though the strategy is right) in that he's running a switch statement on $query, forgetting that $query is a rowset and not a variable expression, therefore $query is not resolved before running switch statement. So the solution would still be to resolve $query through mysql_fetch_assoc(), after including "pages" column in your database table.

Note that '$query' is not rowset. I was assuming that there is a calling page that will pass the '$query' value to this PHP page. The poster will need to update my code above to reflect this incoming value for '$query'.
Re: Help Your Girl O Programmers In The House! by csharpjava(m): 9:34am On Sep 06, 2012
mitey:
while($row = mysql_fetch_assoc($query)){
echo "<th width='200' align='center' ><a href='".$row["cat_name"].".html? cat_id=". $row["cat_id"]. "'<b>". $row["type"] . "<img src='images/".$row["cat_image"]."' width='200' height='200' /></a>Price: ".$row["price"]."<br /><b> Quantity:</b> <input name= 'qty' size='5'> <br /><a href=''>add to cart</a></th>";
}
echo "</tr>";
}[/font]

Instead of storing the names of the pages in a new table row in the database table, why don't you use the $query like this:

if($query){
echo "<tr>";
while($row = mysql_fetch_assoc($query)){
echo "<th width='200' align='center' ><a href='".$row[$query]".html? cat_id=". $row["cat_id"]. "'<b>". $row["type"] . "<img src='images/".$row["cat_image"]."' width='200' height='200' /></a>Price: ".$row["price"]."<br /><b> Quantity:</b> <input name= 'qty' size='5'> <br /><a href=''>add to cart</a></th>";
}

I have not tried this as my computer is not yet setup for PHP but I'm sure this should work.
Re: Help Your Girl O Programmers In The House! by DualCore1: 11:47am On Sep 06, 2012
have a database table holding all your items
table: items
fields: item_name, item_id

have another db table holding all your categories
table: categories
fields: cat_id, cat_name, price, item_id


Create a shopping cart page.

item_query = mysql(select item_id from items)
while(item_row = mysql fetch(item_query)){
category_query = mysql (select all from categories table where item_id = item_row['item_id'])

while(category_row = mysql fetch (category_query){
//go on to list cat details and your other table voodoo.
}
}

Forgive me if its not very clear but really its the simplest way of getting your work done and in the future if you add more items for sale you only need to update the database with the item and its categories. You don't need to update your code. Code is for presentation, database is for storage. Increase in items shouldn't cause an increase in codes...it should naturally cause an increase in the storage (database).

In summary:
The first while loop in my code:
Loop through all your items and dynamically put them in a seperate <div>.

The second while loop in my code:
Then inside each <div>, loop through the categories for the given item and add the buy now link and other things to each category.

Use the item_id as a primary key in items table and a foreign key in categories table.
Re: Help Your Girl O Programmers In The House! by kodewrita(m): 4:12pm On Sep 06, 2012
I am guessing at what you are trying to achieve, I am also making the following assumptions:

you want the three links to reflect books.html?catid=1 , gadgets.html?catid=2

thats why I am pasting the code below(I have altered it a bit to make it readable):

<?php
//connect to server
include('config.php');
$sql = "Select * from category";
$query = mysql_query($sql);
?>
<html>
<head>
<title>Shopping Cart</title>
</head>
<body>
<center>
<img src="images/carton cahrt.jpg" />
<br />
<table>
<form>
<tr>
<td width="200"><input type="submit" name="goods" value="Goods For sale" /></td>
<td width="200"><input type="submit" name="basket" value="Basket Content" /></td>
<td width="200"><input type="submit" name="order" value="Order" /></td>
</tr>
</form>

<?php if($query){ ?>

<tr>

<?php while($row = mysql_fetch_assoc($query)){ ?>

<th width='200' align='center' >
<b>
<a href='<?php echo $row["type"];?>.html?cat_id=<?php echo $row["cat_id"]; ?>'>
<?php $row["type"];?>
</a>
<a href='books.html?cat_id=<?php echo $row["cat_id"]; ?>'>
<img src='images/<?php echo $row["cat_image"];?>' width='200' height='200' />
</a>
Price: <?php echo $row["price"];?><br />
<b> Quantity:</b>
<input name= 'qty' size='5'> <br />
<a href=''>add to cart</a>
</th>
<?php } ?>
</tr>
<?php } ?>
</table>
</center>
</body>
</html>

I am curious, why are you using form buttons to link pages together at the top when you can simply use a link.



Ideally, you shouldnt even be altering that books.html link. its wrongly named.

You need to have category.php and your code would look like this:

<?php while($row= mysql_fetch_assoc($query)){ ?>
<td>
<a href='category.php?cat_id=<?php echo $row["cat_id"]; ?>'>
<span><?php echo $row["type"]; ?></span>
<span> <img src='images/<?php echo $row["cat_image"]; ?>' width='200' height='200' /></span>
</a>
<span>Price: <?php echo $row["price"];?></span><br />
<span><b> Quantity:</b></span>
<input name= 'qty' size='5'> <br />
<a href=''>add to cart</a>
</td>
<?php } ?>


On the category.php page, simply check the GET array for the right variable like so:


<?php if(isset($_GET["cat_id"])){?>
$catid = stripslashes($_GET["cat_id"]); //yes I know you can just pick the array variable but if this is not an academic exercise, then you need to add some basic security hence the stripslashes(). that doesnt mean its secure oh. read more about how to secure PHP applications.

//then load your page contents for that category by writing code after this comment.
<?php } //else{ this is the part where you do error processing if this page is accidentally loaded.?>



Hope I did not confuse you more.
Re: Help Your Girl O Programmers In The House! by silverluci(f): 2:10pm On Sep 13, 2012
thanks guys you are simply the best. i used some of the ideas i got here and it worked. here is the code:

<?php
if($query){
$cat_ids = array();
echo "<tr>";
while($row = mysql_fetch_assoc($query)){
$cat_ids[] = $row["cat_id"];
echo "<th width='200' align='center' ><a href='productpage.php?cat_id=". $row["cat_id"] . "'><b>". $row["type"] . "
</a></th>";
}
echo "</tr>";
echo "<tr>";
for($i = 0; $i < count($cat_ids); $i++){
displayRandomProduct($cat_ids[$i]);
}
echo "</tr>";
}
?>
i simply created a page called productpage.php and referenced the cat_id. when i was through i started smiling like a she-goat. i really grateful nairlanders.

2 Likes

(1) (Reply)

American Company Pays Nigerians To Learn Computer Programming / How Do I Disable The Cancel Button On The Top Corner Of Forms In C#? / Things U Must Know In Programming

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 57
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.