minitauros 151 Junior Poster Featured Poster

Could you post what's on line 142?

minitauros 151 Junior Poster Featured Poster

You should checkout the DateTime class.

Example:

<?php
$date_1 = new DateTime;
$date_2 = new DateTime;

$date_1->setDate(2015, 02, 01);
$date_1->setTime(0, 0, 0);

$date_2->setDate(2015, 02, 05);
$date_2->setTime(0, 0, 0);

$diff = $date_1->diff($date_2);
echo '$diff: ' . $diff->format('%d days') . '<br>';

// OR:
$date_1->add(new DateTimeInterval('P1Y'); // Adds 1 year to $date_1, check out the DateTimeInterval class.
echo '$date_1 is now: ' . $date_1->format('Y-m-d H:i:s') . '<br>';
minitauros 151 Junior Poster Featured Poster

Yes. A larger screen will cost more resources to render. Working with a 1920 pixel wide website on a mobile phone isn't something most people want - you'd have to scroll all the time to find the content you want to see.

Next, if you have a slow internet connection and need to download large Javascript, CSS and image resources, a website will take longer to load. Also if your phone is slow, loading more resources and keeping them in memory will use up more of the available resources.

So yes, it's both the size of the resources and the complexity of the actions they execute. And maybe more, but this is what I know.

minitauros 151 Junior Poster Featured Poster

Oh yeah I wasn't trying to say anything bad about your code, I was just really wondering if it would matter uppercasing or lowercasing the whole string before converting it :).

diafol commented: no worries +15
minitauros 151 Junior Poster Featured Poster

I mean the size of resources like CSS, Javascript, etc., and if they're optimized to work as fast as possible.

minitauros 151 Junior Poster Featured Poster

You search Google for info about the .htaccess file and try some tutorials to create one. Then, if you can't figure out how to create one or if you run into problems, you post your questions here, and we can help you.

Edit: A useful link given by fireburner29 in this post:
http://htaccess-guide.com/

minitauros 151 Junior Poster Featured Poster

What would it matter if you either upper- or lowercase the whole string before converting it? The only thing that matters here is the output, right? :) Which would be the same regardless of if you either upper- or lowercase the input value. (I can't think of an example in which I would find it useful, do you have one?)

minitauros 151 Junior Poster Featured Poster

I've slightly edited the test, and it resulted - as you suspected - in that my solution is twice as fast on average.

function convert($value)
{
    $keys = range("A","Z");
    $values = range(1, 26);
    $falseValue = 0; //or false or null etc- decide
    $conv = array_combine($keys,$values);
    $value = strtoupper($value); //remove this if not req'd
    return (isset($conv[$value])) ? $conv[$value] : $falseValue;
}

$start = microtime(true);
for ($i = 0; $i <= 100000; $i++) {
    convert('C');
}
$end_1 = microtime(true);
echo "<br /><br />$end_1 - $start = " . number_format(($end_1 - $start), 3, '.', '');
echo '<div style="clear: both; height: 0px; height: 2px; background-color: #000; border-top: 1px dashed #fff; border-bottom: 1px dashed #fff;"></div>';


$start = microtime(true);
$letters = range('a', 'z');
$numbers = range(1, 26);
$value = strtolower('C'); // The value in which you want to replace stuff.
for ($i = 0; $i <= 100000; $i++) {
    str_replace($letters, $numbers, $value);
}
$end_2 = microtime(true);
echo "<br /><br />$end_2 - $start = " . number_format(($end_2 - $start), 3, '.', '');

$percentage = number_format(min($end_1, $end_2) / max($end_1, $end_2) * 100, 2, '.', '');
echo "<p>Solution " . ($end_1 > $end_2 ? '2' : '1') . " is $percentage% faster.</p>";
minitauros 151 Junior Poster Featured Poster

Ah, yes, I'd be curious to know that as well.

minitauros 151 Junior Poster Featured Poster

Non-array functions tend to be quicker though.

What do you mean, exactly?

minitauros 151 Junior Poster Featured Poster

You're right, my bad. You cannot set it as a default in PHPMyAdmin/MySQL. You will either have to create a stored procedure for it or edit the data you save every time you save it using PHP (I'd suggest the latter option).

minitauros 151 Junior Poster Featured Poster

What about something like:

<?php
$letters = range('a', 'z');
$numbers = range(0, 26);

echo 'Value before: ' . $value . '<br>';
$value = strtolower($value); // The value in which you want to replace stuff.
$value = str_replace($letters, $numbers);
echo 'Value after: ' . $value . '<br>';
minitauros 151 Junior Poster Featured Poster

My eyes, it burns! Sorry, just had to say that before anyone else can. It's also a bit much to read, and I'm wondering what the goal of the query/procedure is - maybe it can be improved?

minitauros 151 Junior Poster Featured Poster

After reading this post I started wondering what is required nowadays to build an app. Let's take an Android app as an example. I've heard of porters like PhoneGap, that convert your HTML/Javascript to Java (Android for as far as I know), but are there easier ways nowadays? I know very little about Java - my main focus is PHP. I do know a good bit of Javascript, though, so does anyone have experience with creating apps without knowing the main language in which those apps are usually written? Or better yet: what can you do in regard to creating an app when you have only knowledge of PHP and Javascript?

Edit: Hm, maybe this question would be better placed in the Software Development category huh?

minitauros 151 Junior Poster Featured Poster

It's also the amount of resources that need to be loaded and the complexity of the display. The larger the view that needs to be displayed, the slower it gets. The more content that needs to be downloaded, the slower it gets.

At least, for as far as my knowledge goes.

minitauros 151 Junior Poster Featured Poster

You can invalidate your cache by using header(). Example:

header('Cache-Control: private, max-age=0, no-cache');

on the first line of your file. But I don't think that'll work in your example. It only works on the page that offers the file as a download. That means that in your case, you'd have to make a page that gets the contents of your xls file and outputs them directly to the browser with the correct headers.

Have you tried clearing your browser's cache (ctrl + shift + del) and downloading the file again? Or starting your browser in p0rn cough private mode and downloading the file again?

minitauros 151 Junior Poster Featured Poster

What options? First thing that comes to mind is phpinfo();

minitauros 151 Junior Poster Featured Poster

^^

minitauros 151 Junior Poster Featured Poster

It seems like a notice, so it's not an error that will stop your script. What it means is that all the mysql_ functions are deprecated and you are disencouraged to use them. Instead, you should use the mysqli_ functions, or the mysqli or PDO class to execute your queries.

minitauros 151 Junior Poster Featured Poster

Have you tried the bootstrap website? It contains a great starters guide. http://getbootstrap.com/css/ (I know you're asking for a forum, but my interpretation is that you are also looking for a way to learn bootstrap, hence this answer :)).

minitauros 151 Junior Poster Featured Poster

Well, have you checked line 22 in C:\xampp\htdocs\sandbox\config.php? It might contain an error :p.

almostbob commented: :) Kudos +13
minitauros 151 Junior Poster Featured Poster

What about something like:

<?php
if ($user_role == 'superadmin') {
    // Select superadmin and admin users.
    $query = 'SELECT * FROM users WHERE role = "superadmin" OR role = "admin"';
}
elseif ($user_role =='admin') {
    // Select only admin users.
    $query = 'SELECT * FROM users WHERE role = "admin"';
}

// Execute the query

(This is just an example, you should of course fill in the var names and field names and table names you want to use).

minitauros 151 Junior Poster Featured Poster

Ok so let me first rephrase your answer so that I'm sure I understand it correctly.

What you want is:
(1) When an admin is logged in, he may only see users that are "admin".
(2) When a superadmin is logged in, he may see users that are either "admin" or "superadmin".

Is this correct?

minitauros 151 Junior Poster Featured Poster

I'm afraid I cannot! You are ought to put some effort in this of your own :). We can offer help with your problems, not full solutions to your problems.

So what do you have so far, and where is it going wrong? If you have an example of what you've tried so far (and if it includes PHP and MySQL), then post it below and then maybe we can help you.

minitauros 151 Junior Poster Featured Poster

You should probably name your checkbox manually, something like enabled[name][] for each checkbox group.

minitauros 151 Junior Poster Featured Poster

This is because you've outputted something (probably tex) to the browser before your headers were sent. Headers net to be set and sent before you output text to the screen, because the headers usually tell the browser what kind of stuff it is that you are sending to the screen, and it uses that information to determine how to display that what you're outputting.

minitauros 151 Junior Poster Featured Poster

What's not working? What's happening? What do you want to do?

Obviously you still need to add your own code for updating your database to my example.

minitauros 151 Junior Poster Featured Poster

Well, even though you are setting error messages, you don't check if those error messages are set anywhere, and you don't generate an error based on the error messages. So in your code, it seems to me that it is a waste of lines, time and resources to even set them :p. You should generate/throw errors instead of just setting error messages. The error message you are seeing, is because the mail() function is giving an error, since that's the only thing that's being checked in the if/else.

I've added the error check in the example below:

<?php
if ($_POST["submit"]) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $contactno = $_POST['contactno'];
    $city  = $_POST['city'];
    $datepicker = $_POST['datepicker'];
    $persons = $_POST['persons'];
    $message = $_POST['message'];
    $from = 'Demo Contact Form';
    $to = 'imti321@gmail.com';
    $subject = 'Message from Contact';
    $body = "From: $name\n E-Mail: $email\n Ph-No:$contactno\n City:$city\n Date:$datepicker\n No-Of-Persons:$persons\n Message:\n $message ";

    $errors = array();

    // Check if name has been entered
    if (!$_POST['name']); {
        $errors[] = 'Please enter your name';
    }
    // Check if email has been entered and is valid
    if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)); {
        $errors[] = 'Please enter a valid email address';
    }
    //Check if message has been entered
    if (!$_POST['message']); {
        $errors[] = 'Please enter your message';
    }
    //  Check if simple anti-bot test is correct
    if ($human !== 5); {
        $errors[] = 'Your anti-spam is incorrect';
    }

    // Check for errors!
    if ($errors) {
        echo '<p class="errors">';
        foreach ($errors as $error) {
            echo 'Error: ' . $error . …
minitauros 151 Junior Poster Featured Poster

You might want to check out some tutorials on using the float CSS rule by the way :p.

minitauros 151 Junior Poster Featured Poster

No no, "float" is a style property, you'd have to put it in your CSS ;).

So, instead of float="right", use style="float: right;" or put a float: right; in your stylesheet for the element it needs to be applied to.

minitauros 151 Junior Poster Featured Poster

I don't really get what you're asking here. What exactly is is that you want help with? Writing PHP to display records? Then you'd have to be a bit more specific about what information you want to display. So could you clear up your question a bit?

minitauros 151 Junior Poster Featured Poster

You can't. You would have to either have to lock down your website for everyone or leave it open to everyone. And a website that is publically accessible will be readable and will thus be copyable.

You can try to prevent some stuff by disabling right mouse clicks, for example, but you really cannot prevent all copying, as long as the HTML source code can be read (and it can, if your website is publically accessible).

minitauros 151 Junior Poster Featured Poster
<?php
$min = 0;
$max = 100;
$random_number = mt_rand($min, $max);
printf('Your random number is %d', $random_number);
minitauros 151 Junior Poster Featured Poster

HTML:

<form  action="enableprofile1.php" method="post">
    <input type="hidden" name="id[]" id="id[]" value="<?php echo $sn; ?>">
    <input type="checkbox" name="enable[]" id="enable[]"  value="1"  <?php if($en=='1'){ echo 'checked'; } ?>>
    <input type="submit" name="save" value="Save" class="fontBold">
</form>

PHP:

<?php
foreach ($_POST['id'] as $i => $id) {
    $enable = $_POST['enable'][$i];

    if (!$enable)
        continue;

    // Do whatever you want here.
}

If you use input names like "id[]", the POST values will be read as an array by PHP, enabling us to use (for example) a foreach() loop to loop through them.

minitauros 151 Junior Poster Featured Poster

Well, that sounds like there is no easy solution. You'd just have to find out what wp_get_current_user() does, where it comes from, when it should be included and why it isn't included in your file. Or find someone with the same problem, but it doesn't really sound like a much occurring problem ;p.

minitauros 151 Junior Poster Featured Poster

Meh, I still can't get it working :(. Luckily it's not that important for testing stuff locally, so I'll just leave it be for now. Thanks for your reply!

minitauros 151 Junior Poster Featured Poster

Does anyone know how to install a new locale on Apache that comes with Xampp for Windows? I'm trying to find an answer with Google but it only shows results for "local" instead of "locale" -_-.

(I want to install a Dutch locale. It might even be in there already but I can't find out if it is, and I can't get it working).

minitauros 151 Junior Poster Featured Poster

There's nothing wrong with the query, there's something wrong with your PHP: mysqli_query() does not return the results directly; it returns a query resource kind of thing. You still need to fetch the results using (for example) mysqli_fetch_assoc().

minitauros 151 Junior Poster Featured Poster

Well, I guessed that you wanted to know the ID of the song for which the user is voting, so I thought: let's pass that data to the action page. I think you should use the data in $_POST['song_id'] instead of the data in $row['song_id'], which doesn't exist any more when the form is submitted; only the POST data is sent with the request.

minitauros 151 Junior Poster Featured Poster

Same to you! :)

minitauros 151 Junior Poster Featured Poster

As I said, you should either include your buttons in a <form>, or you should use regular links that send GET data.

<?php
while($row = mysqli_fetch_array($table))
{
    ?>
    <tr>
        <td>
            <?php echo $row['song_id']; ?>
        </td>
        <td>
            <?php echo $row['song_name']; ?>
        </td>
        <td>
            <?php echo $row['janr_name']; ?>
        </td>
        <td>
            <?php echo $row['likes']; ?>
        </td>
        <td>
            <?php echo $row['dislike']; ?>
        </td>
        <td>
            <form action="" method="post">
                <input type="hidden" name="song_id" value="<?php echo $row['song_id']; ?>"><!-- This might be useful if you want to identify which song receives a submission. -->
                <input type="image"  name="submit" value="like" src="like.jpg">
                <input type="image"  name="submit" value="dislike" src="2.jpg">
            </form>
        </td>
    </tr>
    <?php
}
minitauros 151 Junior Poster Featured Poster

jQuery would indeed be excellent for this task. If you don't know it yet, I suggest you read some tutorials. What Traevel says will also be much clearer if you have a basic understanding of what you can do with Javascript / jQuery.

minitauros 151 Junior Poster Featured Poster

You could include a form in each of your table rows. That form should then include the like/dislike buttons.

Or you can make those buttons pass on GET variables to your page by linking to (for example) "your_page.php?action=like". Your form passes (in this case) POST data to your page. A simple link would pass GET data. You wouldn't need a form, but you need to obtain your data using $_GET instead of $_POST.

minitauros 151 Junior Poster Featured Poster

Don't get me wrong here, but are you sure you know how to use the rest of that script if you don't even know how to output such a thing? :p

Because seeing that script I don't get the impression that you're new to scripting.

Anyway, usually you perform a SELECT query on your database and use the results on your page.

E.g.

<?php
$query = 'your_query';

// (Execute your query).

echo '<p>Welcome, ' . $result['name'] . '</p>'; // (Where $result holds a query result)
minitauros 151 Junior Poster Featured Poster

Well, any <input> of which you want to use the value must (generally spoken) be inside <form> element. When you press the submit button, all input inside the <form> element that submit button is in is gathered and sent to the url that you specify under the form's action attribute. So, if you have buttons or inputs outside a form element, they won't work (except if you use Javascript to create a "workaround").

minitauros 151 Junior Poster Featured Poster

O my god I thought that $message was meant to be overwritten by $v1, but now that I read these new messages you may very well be right, Traevel :p.

minitauros 151 Junior Poster Featured Poster

Well, there seems to be missing an INSERT or UPDATE query to insert/update the like/dislike, and there seems to be missing a <form> that the buttons use.

So where/when exactly is stuff going wrong?

minitauros 151 Junior Poster Featured Poster

Well, same to you :).

minitauros 151 Junior Poster Featured Poster

What JorgeM says, plus: my best guess is that it has something to do with the contents of $message. Have you tried omitting $message from your CSV to see if styling still comes through?

minitauros 151 Junior Poster Featured Poster

So all a shop's products are saved inside a big TEXT field? Isn't the whole idea of SQL that you - in this case - should save all your products in one table, say "products"? That would probably increase performance by itself.

For example:

+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| id    | int(11)      | NO   | PRI | NULL    |       |
| name  | varchar(64)  | NO   |     | NULL    |       |
| price | decimal(6,4) | NO   |     | NULL    |       |
+-------+--------------+------+-----+---------+-------+

For the rest, usually a VARCHAR is faster to search through than a TEXT field (because of the size). A field containing a lot of text is usually slower to search trhough than a field that contains less text. You can use the LIKE comparison operator to search your text. For as far as I know, that's the best you can get in most situations.