Jump to content

mweingand

New Members
  • Posts

    6
  • Joined

  • Last visited

mweingand's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. unfortunately I don't have the knowlage on how to create a dynamically produced page, so Im looking for help at the level I'm at now. If you have suggestions of what I've done wrong in this thread, I'd aprriciate it.
  2. Please be gentile I am new to PHP and I am struggling with what I thought would be an easy, normal, standard call to the db to get a variable based on a constant, to place in an 'li' tag. jcbones was helpfull in getting me the code below. When I put this in place there are a few strange things that happen. 1. The output it only the first charactor of the field, that I am trying to pull. Base_Price. example: the first charactor in 1670.00 is a 1. 1 shows in the output only. 2. The query looks to be tryign to call a field that I do not have. TYPE=? So I changed this to be WHERE Unit_Product='u'. I edited for three of my product to have a 'u' in this field. It pulls fine manually. ******(Info from jcbones)******* /*Pull all of your relevant data from the database in one query. I suppose you are using an auto_incremented ID, or some other UNIQUE key. You can store all the data in an array, and then echo out that array as the base price. */ /*If you cannot re-build the whole page to make it dynamic, this is my suggestion. */ <?php $link = mysqli_connect("localhost", "my_user", "my_password", "world"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $type = "mixers"; /* create a prepared statement */ if ($stmt = mysqli_prepare($link, "SELECT record_number, Base_Price FROM Product WHERE Type=?")) { /* bind parameters for markers */ mysqli_stmt_bind_param($stmt, "s", $type); /* execute query */ mysqli_stmt_execute($stmt); /* bind result variables */ mysqli_stmt_bind_result($stmt, $product, $price); /* fetch value */ while(mysqli_stmt_fetch($stmt)) { $products[$product] = $price; } /* close statement */ mysqli_stmt_close($stmt); } /* close connection */ mysqli_close($link); ?> /* After this, anywhere you need the price you can echo out the array. */ <h2 align="center" class="topper"><a href="dynamic_mixer_smx800e.html">SMX 800E <br /> Mixer</a></h2> <ul> <li>Length 27" Tube</li> <li>800 Watts </li> <li><?php echo $product[‘1077”]; ?></li> </ul>
  3. First off thanksjcbones for gettting me close. NOW !!!HELP Anyone!!!!!!!! Please OK here is some questions after some testing. I'll put what I've done, results, Questions and then my code. What I've done. After no sucess. I took out TYPE=? in the query and made the query like this. "SELECT Product_Code, Base_Price FROM products WHERE Unit_Product='u'" I got an s in my output. I found that this was coming from the first letter "only" in the Product_Code field of the first record it found matching the query. I tried changing the field to verify it was coming from that field. It was, but again only the "first charactor". I then changed the output line to what I thought it would be, using as the Constant, "SMX800E" (coming from Product_Code but this had no effect. I also noticed that we were not grabing $price so I changed that to. <li><?php echo $price['SMX800E']; ?></li> I am getting only the first charactor of the Base_Price field. I changed the amount to verify. I then took out SMX800E from the variable and put in a numeric '1' and it pulled the second charactor only from the field so I tested by changing the number to a 2,3,4 and so on. It's just grabing one charactor from the field in that place holder. 0,1,2,3,4 place. So the two issues Im having. Im not able to pull using a variable and I am only getting one charactor in my output. here is my code. ********************* $type = "mixers"; /* create a prepared statement */ if ($stmt = mysqli_prepare($link, "SELECT Product_Code, Base_Price FROM products WHERE Unit_Product='u'")) { /* bind parameters for markers */ mysqli_stmt_bind_param($stmt, "s", $type); /* execute query */ mysqli_stmt_execute($stmt); /* bind result variables */ mysqli_stmt_bind_result($stmt, $product, $price); /* fetch value */ while(mysqli_stmt_fetch($stmt)) { $products[$product] = $price; } /* close statement */ mysqli_stmt_close($stmt); } /* close connection */ mysqli_close($link); ?> <h2 align="center" class="topper"><a href="dynamic_mixer_smx800e.html">SMX 800E <br /> Mixer</a></h2> <ul> <li>Length 27" Tube</li> <li>800 Watts </li> <li><?php echo $price['SMX800E']; ?></li> </ul>
  4. !!!!HELP Anyone!!!!!!!! Please OK here is some questions after some testing. I'll put what I've done, results, Questions and then my code. What I've done. After no sucess. I took out TYPE=? in the query and made the query like this. "SELECT Product_Code, Base_Price FROM products WHERE Unit_Product='u'" I got an s in my output. I found that this was coming from the first letter "only" in the Product_Code field of the first record it found matching the query. I tried changing the field to verify it was coming from that field. It was, but again only the "first charactor". I then changed the output line to what I thought it would be, using as the Constant, "SMX800E" (coming from Product_Code but this had no effect. I also noticed that we were not grabing $price so I changed that to. <li><?php echo $price['SMX800E']; ?></li> I am getting only the first charactor of the Base_Price field. I changed the amount to verify. I then took out SMX800E from the variable and put in a numeric '1' and it pulled the second charactor only from the field so I tested by changing the number to a 2,3,4 and so on. It's just grabing one charactor from the field in that place holder. 0,1,2,3,4 place. So the two issues Im having. Im not able to pull using a variable and I am only getting one charactor in my output. here is my code. ********************* $type = "mixers"; /* create a prepared statement */ if ($stmt = mysqli_prepare($link, "SELECT Product_Code, Base_Price FROM products WHERE Unit_Product='u'")) { /* bind parameters for markers */ mysqli_stmt_bind_param($stmt, "s", $type); /* execute query */ mysqli_stmt_execute($stmt); /* bind result variables */ mysqli_stmt_bind_result($stmt, $product, $price); /* fetch value */ while(mysqli_stmt_fetch($stmt)) { $products[$product] = $price; } /* close statement */ mysqli_stmt_close($stmt); } /* close connection */ mysqli_close($link); ?> <h2 align="center" class="topper"><a href="dynamic_mixer_smx800e.html">SMX 800E <br /> Mixer</a></h2> <ul> <li>Length 27" Tube</li> <li>800 Watts </li> <li><?php echo $price['SMX800E']; ?></li> </ul>
  5. First off, Thanks Guru. I really thought I totally understood this but I am not even getting an error anymore to point me in the right direction. Can you see where I may have gone wrong? I changed the query to use record_number as I do not have all Product_Code 's for all the units but for now I have good record_number 's. I then figured that if I put the record_number in the echo to call the variable in, I'd see the Base_Price. <?php echo $product['1072']; ?> Im also not sure what Type=? is doing in my query. When I change the query as follows, (SELECT record_number, Base_Price FROM products WHERE Unit_Product='u') I get an 's' in my output field. At least it's pulling something, just not sure what. Here is my code with user name and password omitted. Any help is greatly appriciated. ******************************************************************************* <div align="center">PHP coding for price only in 'li' tag.</div> <div> <?php $link = mysqli_connect("localhost", "users_name", "pass", "db"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $type = "mixers"; /* create a prepared statement */ if ($stmt = mysqli_prepare($link, "SELECT record_number, Base_Price FROM products WHERE Type=?")) { /* bind parameters for markers */ mysqli_stmt_bind_param($stmt, "s", $type); /* execute query */ mysqli_stmt_execute($stmt); /* bind result variables */ mysqli_stmt_bind_result($stmt, $product, $price); /* fetch value */ while(mysqli_stmt_fetch($stmt)) { $products[$product] = $price; } /* close statement */ mysqli_stmt_close($stmt); } /* close connection */ mysqli_close($link); ?> <h2 align="center" class="topper"><a href="dynamic_mixer_smx800e.html">SMX 800E <br /> Mixer</a></h2> <ul> <li>Length 27" Tube</li> <li>800 Watts </li> <li><?php echo $product['1072']; ?></li> </ul> </div>
  6. I'm new to PHP and I have an html page I would like to pull specific data into certain areas on the page that I will modified for php. Here are some details. The page is a static html page that has the prices of 40+ products in a standard <li> list. When I update the prices in our database through our shopping cart, I have to change these prices manually in the html. https://www.novon.com/dynamic_mixers.html. It would be great if I could link the field for Base_Price in the products table to each affiliated <li> tag, I am pulling all the data I need into ($results) and can display it all but I don't know how to get just the single products Base_Price in my <li> tag. <?=$row['Base_Price'] ?> I know this code is not correct but to get the point across, can I create a variable that I define in each <li> tag with a statement like,,,, <?=$row['Base_Price with Product_Code=123456'] ?> I could create a new SQL query for each <li> like "SELECT Base_Price from Products WHERE Product_Code='123456' ", but that's a lot of calls to the DB and a lot of code on the page. And just so I weed out the hard core coders, I can not rebuild the entire page. This is too big of a project for me and my limited coding with PHP. Can anyone help?? Thanks in advance Michael
×
×
  • 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.