-
Posts
3,372 -
Joined
-
Last visited
-
Days Won
18
Everything posted by Muddy_Funster
-
how to make this pagination work with search results?
Muddy_Funster replied to lovephp's topic in PHP Coding Help
No, you can't bind column names as parameters. This is going back to what I said about maintaining dynamic where clauses. -
And your point is caller? The link in my sig is to a reputable blogging host, not some random zip file that could contain god knows what viruses. I don't ask anyone to click the link in my sig and it's certainly not a requirement that people do it in order for help to be provided. You're comparing apples to oranges. To be honest I had forgotten it was even there, now you have reminded me I'll probably remove it as most of the content is seriously out of date. That's Right, it is "PHP Coding Help", but you didn't post any code and your not asking for help, your asking for someone to do the work for you. The point of this forum is to provide guidance and tuition for those that have hit a block in writing their own code. Commonly those proffering help on this forum will take the time and effort to write longer posts than just the fix requires, this is because just fixing things for people isn't a long term solution. It fixes the code, but not the underlying problem that caused the code to be an issue in the fist place. If you don't want help, just code, then go try another site. If you want real help however then suck it up and do what is asked. This is all for your benefit, not ours.
-
First post on a public forum and you're asking people to download a zip file? Sorry, I don't think so.
-
check value stays unchanged even after form submit?
Muddy_Funster replied to lovephp's topic in Javascript Help
I always find html localStorage ( https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API ) is a quick, easy (and yeah ok, kinda dirty) way to have JS persistence, sessionStorage would probably be better for your use case though. -
Exactly what I was going to suggest next. If the data stored isn't accurate then you should be sorting that, not trying to make a workaround for it. Also, your countdown is granular to the second and your date is only to the day. The whole field type should be changed to datetime and the insert script is what you should be looking to alter, not the display one. What do you mean? It already is, that's kinda the issue.
-
I'm still not sure about the code you are using. var is used in JS and the $ prefix is used in php, so it looks like you are mashing the two together. What is $time? and where does it come from?
-
add it where? in JS or in PHP?
-
I think the issue here is really just coming from a lack of understanding the capabilities of the processes you are working with. The following is a basic representation of the processing when using a web browser: Step 01 > Server gets an http request from client Step 02 > Server runs php using any header information passed in the http request Step 02.1 > Server connect to backend storage Step 02.2 > Server retrieves data from backend storage Step 02.3 > Server processes data from backend storage Step 03 > Server finishes running php and buffers result Step 04 > Server returns result of php script to requesting client. -------------- Step 05 > Client receives the result from the server into buffer Step 06 > Client browser processes the header information in the server response Step 07 > Client browser processes client side scripting (such as javascript) stored in the header Step 08 > Client browser applies css styles to buffered page content Step 09 > Client browser renders page content to screen Step 10 > Client browser processes client side scripting in the page body Step 11 > Client Browser allows interaction with the page in the browser --------------- Step 11 > Client browser submits user data to server in form of http request Step 12 > GOTO Step 01 The first break is where the server relinquishes the data to the client - at this point php will no longer run. Thus all data the php needs to work with will need to be present BEFORE this happens. The second break is where the client would send data back to the server, all relevant data from the page that is required to go to the server must be included in the http header at this time or the server will not know anything about it. While some basic visual effects can be "programmed" into CSS, complex manipulation of DOM elements requires something a little more suited to the task. To debug the problems you are having you will need to follow your data on it's way though the process above and see at which point it's getting lost. Then you will know what side of things you need to look at: server->transport->client.
-
<?php while($row_product1 = mysqli_fetch_assoc($result_product)){ every one of those lines is a loop, I was saying that by applying the order to the actual query you will only need one loop, not one for every value in specials.if you want a better answer ask a better question: Generaly include: 1>what are you trying to accomplish - in detail 2>what result to you get just now Specifically for this question include: 1>what order are you trying to get the products in? 2>what is stored in specials if it's not 0,1,2,3,4,5 or 9 ? 3>are you expecting to get results from the database where the specials column does not have one of the values (1,2,3,4,5,9) and if so how are you expecting to handle it? 4>what is this form element that you are trying to add supposed to do?
-
change query string to: SELECT * FROM products WHERE NOT specials='0' AND product_publish='y' ORDER BY specials ASC then just echo out from a single loop.
-
XPath and searching in a XML document
Muddy_Funster replied to andyfarang's topic in PHP Coding Help
Quite welcome, could you mark post as answered please if there's nothing more you need on it? -
ok, change the following and let us know what it gives you: $id = $db->lastInsertId('id'); becomes $id = $db->lastInsertId(); var_dump('last-insert-id = '.$id);
-
sorry....what?
-
XPath and searching in a XML document
Muddy_Funster replied to andyfarang's topic in PHP Coding Help
For that scenario you would be better using the method @barand has described, that way you only need to loop through the 200 id's that you want to update, rather than having to loop through the 1000 products and then the 200 id's. assuming your 200 id's are in an array: //load in your xml element as before - going to call it $xml in this //also going to add a bit to build some of the query string to save another loop $setStr = ""; foreach($idArray as $key=>$id){ $prod = $xml->xpath("/eshop/product[id={$id}]"); $update[$id] = $prod->price; $setStr .= "\tWHEN {$id} THEN {$prod->price}\n" } that will give you an array of the prices that you want to update in the database ::Edit - changed $setStr to set both values directly as source id data feed rather than user input. -
XPath and searching in a XML document
Muddy_Funster replied to andyfarang's topic in PHP Coding Help
You just need to add another stage to the process. Pull out the products with the xpath query and then create an array of product objects, then iterate through that array to find the product with the id that you want and retrieve the info you need: $xmlObj = new SimpleXMLElement($xmlData); $productsArray = $xmlObj->xpath('/eshop/product'); //... //do some stuff //... //then when you need it: foreach($productsArray as $idx=>$productObj){ if($productObj->id == $knownIdYourLookingFor){ $currentProductPrice = $productObj->price; } That gets you what you're looking for - however, it's not the best solution for a busy cart system, what would be better would be to re-index the $products array so that the keys reflect the product id. then you can quickly refferance it multiple times without having to repeatedly loop through it. //top part stays the same foreach($productsArray as $idx=>$productObj){ $products[$productObj->id] = $productObj; } unset($productsArray); // don't really nead this, but as product lists can be sizable there's no point having multiple coppies about the place //now you can grab what you need, when you need it directly from the $products array $priceYouWant = $products[$idYouKnow]->price; Let us know how that works for you. ::Edit - missed out a vary important "not" - fixed now -
-
Without knowing what is stored to define whether a like has been attached and what exactly you should be getting back we won't know if there is an issue with the query, syntactically the php looks ok but it's always a worthy debugging step to fling in a var_dump($stmt_liked->errorInfo()) just after the query to see if it's doing what it should be.
-
how to make this pagination work with search results?
Muddy_Funster replied to lovephp's topic in PHP Coding Help
There should be more to that PDOException error that tells you exactly what the problem is - such as parameter type mismatch, different number of parameters to placeholders etc. Some other things though: Purely dynamic WHERE clauses are a big potential security flaw, not to mention an absolute ball ache to manage, and you should try really hard to avoid using them at all. If you want to be able to use COUNT(*) in a meaningful way you should alias it eg. "SELECT COUNT(*) as totalNumber FROM ..." There is no need to prepare() a flat SQL statement such as "SELECT something FROM somewhere" as there are no parameters being passed to it - you should user PDO::query - for SELECTs - or PDO::exec for other query types in this situation. Also, rather than looping through the $param array it would be more efficient if you just passed the array into the $stmt->execute($param) like that. To do this though you will probably have to change your $and_terms[] to "{$field} = ? " and then your $param[] = array($_GET[$field]) As PARAM_STR is the default for PDO parameter types and you are not applying that conditionally there is no need to have it in there. -
what does a var_dump($ticket_title) get you?
-
If you only have a single item in the array, why make it an array? Anyway, it tells you that the array contains objects, so try: $whatYouWantIs = $yourArray[0]->name; you can also use a foreach to extract all the names: foreach($yourArray as $k=>$v){ $whatYouWantIs[] = $v->name; } $thirdName = $whatYouWantIs[2];
-
how to post only user selected values in a form
Muddy_Funster replied to michelle1404's topic in Javascript Help
If you have jQuery linked it should look something a little bit like this: $('#addformName').on('submit', function(e){ e.preventDefault(); var selectVals =[]; $('#addformName select').each(function(idx, elm){ if(elm.val() > 0){ selectVals[idx] = elm.val(); } }) if (selectVals.length() >= 1){ $.ajax({ method: 'POST', url: 'path/to/page.php', data: selectVals, success: function(data){ alert(data); } }) }); That's likely not going to work as is, and the ajax definitely won't because the url is nonsense, but it covers the core of what you are trying to do. -
Mimicking autoincrement primary key using PHP
Muddy_Funster replied to NotionCommotion's topic in MySQL Help
this is bad. why are you doing what you are doing? IMHO You need to change your DB model. That said: yes, if you know given conditions of this mock key system then you could code the values into the app level and push them into the DB. If I knew what those constraints were I'd help you, but, thankfully, I don't. Seriously though: fix the back-end now and save yourself much pain in the future. -
how to post only user selected values in a form
Muddy_Funster replied to michelle1404's topic in Javascript Help
If your using jQuery then: $('#addnameform').on('submit', function(e){ e.preventDefault(); //do your thing } -
how to post only user selected values in a form
Muddy_Funster replied to michelle1404's topic in Javascript Help
For some reason var form = document.querySelector("form"); isn't doing what you think it should - var form is null on the next line. obviously you can't assign an event to a null element. I would suspect giving the actual form a name (or at the very least an ID) would go some ways to helping you out of this specific issue.